Easly Deploy Static Website to Kubernetes without the custom docker images

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:

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

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

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