In this post, we’ll cover the steps to deploy a Hexo blog on Kubernetes using GitHub Actions. This setup automates the build, containerization, and deployment of the blog to your Kubernetes cluster.
Prerequisites
- Hexo Installed Locally: Ensure Hexo is installed and your blog is set up.
- Kubernetes Cluster: A running Kubernetes cluster with
kubectlaccess. - Docker Registry: A registry to store your container images.
- GitHub Repository: Store your Hexo blog project in a GitHub repository.
- cert-manager: Installed in your Kubernetes cluster for TLS certificates.
Step 1: Containerize Your Hexo Blog
Generate Hexo Static Files:
1
hexo generate
Create a Dockerfile:
1
2
3FROM nginx:alpine
COPY public /usr/share/nginx/html
EXPOSE 80Build and Push the Docker Image:
1
2docker build -t <registry>/hexo-blog:latest .
docker push <registry>/hexo-blog:latest
Step 2: Kubernetes Configuration
Deployment YAML
1 | apiVersion: apps/v1 |
Service YAML
1 | apiVersion: v1 |
Ingress YAML
1 | apiVersion: networking.k8s.io/v1 |
Step 3: GitHub Actions Workflow
Create a .github/workflows/deploy.yml file in your repository:
1 | name: Deploy Hexo Blog |
Step 4: Verify the Deployment
Check the Pods:
1
kubectl get pods -n <namespace>
Access the Blog:
Navigate tohttps://<your-domain>in your browser.
Conclusion
By automating the build and deployment of your Hexo blog using GitHub Actions, you save time and ensure consistency in your releases. This setup is scalable and can be extended with monitoring and logging for production environments.
Let me know if you have any questions or need further assistance!