Deployed my blog on Kubernetes pic.twitter.com/XHXWLrmYO4— Dex (@dexhorthy) April 24, 2017
Generate a static blog
To generate an example Jekyll blog.
jekyll new test_blog cd test_blog jekyll build
Build Docker Image
Add this Dockerfile in the root directory then
docker build . -t rhan888:blog.
FROM nginx EXPOSE 80 COPY _site/ /usr/share/nginx/html
This creates a docker image from the nginx base image. Nginx serves static content from root directory under default settings and typically runs on 1mb of memory and negligible CPU.
Now upload this image to a Docker registry of your choice.
Deploy Docker Image to Kubernetes
Create a Pod
Create a new file named
blog-deployment.yml. It will be used later to create an a pod on your cluster.
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: blog spec: replicas: 1 template: spec: containers: - env: image: rhan888/blog:latest imagePullPolicy: Always name: blog ports: - containerPort: 80
To “run” this file, supply the file to
kubectl create -f blog-deployment.yml
Now a deployment is created on the cluster. However, it is only accessible from within the cluster.
Create a Service
We need to expose the port and bind it an external IP. We achieve this by creating a service. The
blog-service.yml is the configuration file for this service.
apiVersion: v1 kind: Service metadata: name: blog spec: type: "LoadBalancer" ports: - name: "http" port: 80 targetPort: 80 selector: name: blog
Supply kubernetes with the above config:
kubectl create -f blog-service.yml
Now your static blog is deployed on Kubernetes, up and accessible from external IP.
We can deploy a static website to Kubernetes with minimal effort.