This Project Include:
- Containerizing the Static website
- Minikube Clusters
- ArgoCD for Contineuous Deployment
- Helm Charts for Parameterizing K8S Manifests
- Github Actions for Contineuos Integration
- DockerHub for Storing Images
Video Demonstration: https://youtu.be/1PRMywtWoJA?feature=shared
Instructions to Deploy
Install Prerequistics
- Minikube: To manage kubernetes cluster in local
- Kubectl: To pass commands into cluster
- Git: Version Controlling the code.
- Helm: Easier management of Kubernetes Manifests.
Clone the Repository
git clone https://github.com/srngx/devopsifying-app
Create Docker Image
docker build -t /mywebsite .
Start Minikube Cluster
minikube start
Manually Running with kubernetes
Goto the K8S/manifests/ directory and run:
- deployment kubctl apply -f deployment.yaml
- service kubctl apply -f service.yaml
Check status if all service working properly
- kubectl get all
And try to access the service using minikube IP and nodeport Check Minikube IP
- minikube ip
Deploying with helm charts
Optional:
- You can create helm chart and manually edit template but I already did that part
So here is what I did
- helm create mywebsite-chart
- deleted Charts and everything inside templates folder
- and copied both manifests files into templates
- Deleted all comments from Chart.yaml
- Edited values.yaml
file and deleted everything except: yaml replicaCount: 1 image: tag: "v1"
- And Edited deployment.yaml file to parameterized the Image Tab with {{ .Values.image.tag }}
Deploy with helm charts
cd helm
helm install mywebsite ./mywebsite-chart
Github Actions
Creating Repository
- Create a New Github Repository
- Commit these files in the repository
- Add CI file
.github/workflows/ci.yaml
name: helm-CI
permissions:
contents: write
on:
push:
branches:
- master
paths-ignore:
- 'helm/**'
- Readme.md
- .gitignore
jobs:
push:
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v4
- name: Setup docker build
uses: docker/setup-buildx-action@v1
- name: Login do DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/mywebsite:${{ github.run_id }}
platforms: linux/amd64,linux/arm64
update-helm-chart:
runs-on: ubuntu-latest
needs: push
steps:
- name: checkout repository
uses: actions/checkout@v4
- name: Update tag
run: |
sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/mywebsite-chart/values.yaml
- name: Commit and push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "srngx"
git add helm/mywebsite-chart/values.yaml
git commit -m "Updated tag in Helm chart"
git push
Generate Dockerhub token
- login to https://hub.docker.com
- Goto to your Account Setting >> Personal Access Token
- Give any name and Generate
- Copy it somewhere to use in next step
Create Repository Secrets in Github
- Goto your Repository Settings
- Under Secrets and Variables goto Actions and create New Repository Secrets
- For username:
- Name: DOCKERHUB_USERNAME
- Secret: - For Password:
- Name: DOCKERHUB_TOKEN
- Secret:
Push everything to github and see if action is running perfectly
ArgoCD
To Autodeploy the new version of site we use Argo CD
Install ArgoCD cluster
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Check argo running status
kubectl get all -n argocd
kubectl get service -n argocd
Our arogocd server service showing ClusterIP
right now but we need to make it NodePort
to access it
Kubectl edit service argocd-server -n argocd
Goto Very bottom of page and Change type: ClusterIP to type: NodePort
and save and exit
Now we should see Nodeport
Accessing the ArgoCD-server
check minikube
and open in browser with appending nodePort Port: http://192.168.49.2:31542
Getting Login Details
- Username is 'admin'
- and password can be found in secrets
To get password
kubectl get secret -n argocd
- locate
argocd-initial-admin-secret
kubectl edit secret argocd-initial-admin-secret -n argocd
- Copy the password which is encrypted in base64
echo UVA1akh0eTlTU295dnozcA== | base64 --decode
- copy the password except
%
sign at the end - and use to login
Create app inside Argocd
- Application Name: mywebsite
- Project Name: default
- Sync Policy: Automatic
- Check on: Self Heal
- Repository URL:
- PATH: helm/mywebsite-chart
- CLUSTER URL: https://kubernetes.default.svc
- NAMESPACE: default
- HELM VALUES: values.yaml
- Click on Create
It will take a second to show everything in sync and healthy.
Now try editing your website code and push it to github and See it will resync after a minute and new tag will be appear on values.yaml file and same tag no. image must be uploaded to dockerhub.
Thanks for Reading!