Easly Deploy Static Website to Kubernetes without the custom docker images

Abdennour Toumi
2 min readOct 8, 2018

--

While building artifacts (docker images) is a best practice at the end of the Build stage in the CI pipeline, you may consider the GIT repository itself as an artifact for a specified GIT commit.

This means you don’t need to ship your code to a new docker image after each change in your code.

Indeed, I discovered today the “species” gitRepo after running kubectl explain pod.spec.volumes.

apiVersion: apps/v1
kind: Deployment
metadata:
name: static-website
spec:
selector:
matchLabels:
app: static-website
template:
metadata:
labels:
app: static-website
spec:
containers:
- name: static-website
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- mountPath: /usr/share/nginx/html
subPath: example-static-website
name: static-website-volume
volumes:
- name: static-website-volume
gitRepo:
repository: https://github.com/abdennour/example-static-website.git

This deployment definition defines:

  • A container initiated from the docker image nginx
  • A volume that is created from the GIT repository of this static website.
  • Mounting of that volume on the container path /usr/share/nginx/html
  • subPath with the same value of the GIT repository name to avoid paths like: /usr/share/nginx/html/<repo-name>/index.html . Rather, you will mount the content of the repository directly onto the root path of nginx.

Deploy it kubectl create -f that-deployment.yaml !

Up? kubectl port-forward <name-pod-created> 8888:80

Then go to http://localhost:8888

Congratulations!

If you made changes to your code, and you want to release it, you just need to set revision property.

volumes:- name: static-website-volume        gitRepo:repository: https://github.com/abdennour/example-static-website.git
revision: 0229f2c228fba8728183878cf58fb078c7612763

--

--

Abdennour Toumi
Abdennour Toumi

Written by Abdennour Toumi

Software engineer, Cloud Architect, 5/5 AWS|GCP|PSM Certified, Owner of kubernetes.tn