Find a Sample code for deployment.
- In our example we are using django code. for github action CI work.
- download the code from below site: https://code-projects.org/invoice-generator-in-django-with-source-code/
- Try to build the code on your location and test and it run on your local.
- Once you see the code running fine. then create Docker image
- write a dockerfile and build the code, and try to run the docker image.
- After you satisfied about the code functionality and working fine.
- Now make git repo. (https://github.com/manjeetyadav19/ci_cd_with_github_argocd1)
- push the code and dockerfile in github. and Plan for github CI by github action
- For Github CI you need to make a directory structure in your source code.
- .github/workflows
- In workflows directory create a github action yaml file.
(https://github.com/manjeetyadav19/ci_cd_with_github_argocd1/blob/main/.github/workflows/docker-image.yml) - This yaml file you can create with the help of already given template on github actions.
- and once your github action yaml file success. than you can create a kubernetes cluster or minikube for microservice deployment.
- In the kubernetes cluster 1st install argocd.
- https://mycloudjourney.medium.com/argocd-series-how-to-install-argocd-on-a-single-node-minikube-cluster-1d3a46aaad20
- after its installed go to argocd UI
- you can link your github repo with ArgoCD and you can create a application where you can define namespace and kubernetes env. for new deployment/services
once argocd installed in kubernetes cluster now you can write Kubernetes Deployment and service file and upload in your github code.
So once you update the code in git repo, argo CD will pull the changes from github repo, and it will deploy the deployment and service yaml file on kubernetes, and you can check the sync option argoCD.
Important cmd and issues comes during deployment in K8s
Log in to Docker Hub
On your laptop, you must authenticate with a registry in order to pull a private image.
docker login
The login process creates or updates a config.json
View the config.json file:
cat ~/.docker/config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "c3R...zE2"
}
}
}
Create a Secret based on existing credentials
If you already ran docker login, you can copy that credential into Kubernetes:
kubectl create secret generic regcred \
--from-file=.dockerconfigjson=~/.docker/config.json \
--type=kubernetes.io/dockerconfigjson
Note:: if you get error in pod deployment and you see the error ImagePullBackOff/ErrImagePull here check in docker config file cat ~/.docker/config.json
if v1 showing here and in logs its trying registry url v2
so it is important pls check the error in logs for pod, if its related v1 to v2, so change accordingly and try again.
New setup on EKS
- install aws cli
- install kubctl
- install helm
- created AWS user and generated Access key under the user need to assign permission to AWS user but i have just give AdminAccess
- created EKS cluster
eksctl create cluster --name my-cluster --region us-east-1 --zones=us-east-1a,us-east-1b,us-east-1
- create argocd namespace
kubectl create namespace argocd
- install helm chart for argocd
helm install argocd argo/argo-cd -n argocd
NAME: argocd
LAST DEPLOYED: Thu Jan 25 08:29:42 2024
NAMESPACE: argocd
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
In order to access the server UI you have the following options:
1. kubectl port-forward service/argocd-server -n argocd 8080:443
and then open the browser on http://localhost:8080 and accept the certificate
2. enable ingress in the values file `server.ingress.enabled` and either
- Add the annotation for ssl passthrough: https://argo-cd.readthedocs.io/en/stable/operator-manual/ingress/#option-1-ssl-passthrough
- Set the `configs.params."server.insecure"` in the values file and terminate SSL at your ingress: https://argo-cd.readthedocs.io/en/stable/operator-manual/ingress/#option-2-multiple-ingress-objects-and-hosts
After reaching the UI the first time you can login with username: admin and the random password generated during the installation. You can find the password by running:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
(You should delete the initial secret afterwards as suggested by the Getting Started Guide: https://argo-cd.readthedocs.io/en/stable/getting_started/#4-login-using-the-cli)
- port forwarding for argocd on local webui
kubectl port-forward service/argocd-server -n argocd 8080:443
- generate login pass for login on argocd webui
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
Argocd Settings
connect repo -
Choose your connection method: - https
CONNECT REPO USING SSH -Repository URL paste here
Cluster
Server
Credential
Name
Namespace -
Project
default
manjeet
Default -
Name - default
Source Repository
*
Destination
*
Cluster Resource ALLOW LIST
Kind Group
* *
Applications
Create
Application Name - test
Project Name - manjeet
Sync Policy - Manual
Source - repository Url - HTTPS
Path - .
Destination
Cluster URL - https://kubernetes.default.svc
Namespace - manjeet
No comments:
Post a Comment