Argo
Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.
Target
Integrate ArgoCD with GitLab and automatically deploy repository data to different Kubernetes clusters.
Task
ArgoCD info
- 10.1.5.100:30080
- Account : admin
- Password : admin
System structure
Helm repo
> You need gitlab repo token to let ArgoCD pull your repo.
> [Create a project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html#create-a-project-access-token)
- helm-nginx folder
. ├── CHANGELOG.md ├── Chart.lock ├── Chart.yaml ├── README.md ├── templates │ ├── deployment.yaml │ ├── extra-list.yaml │ ├── health-ingress.yaml │ ├── _helpers.tpl │ ├── hpa.yaml │ ├── ingress-tls-secret.yaml │ ├── ingress.yaml │ ├── networkpolicy.yaml │ ├── NOTES.txt │ ├── pdb.yaml │ ├── prometheusrules.yaml │ ├── server-block-configmap.yaml │ ├── serviceaccount.yaml │ ├── servicemonitor.yaml │ ├── svc.yaml │ └── tls-secret.yaml ├── values.schema.json └── values.yaml 1 directory, 22 files
My task
- Use Argo to deploy an NGINX service at 10.1.5.100 in the
argotest
namespace. - Change the container tag in a pod and check whether Argo is syncing or not.
- Add k8s cluster (10.1.5.201) to current cluster.
- Use Argo to deploy an NGINX service in another Kubernetes cluster at 10.1.5.201
ps: Nginx k8s yaml files are at gitlab repo.
Steps
Deploy an NGINX Service In-Cluster
- Prepare Helm NGINX Repo
- Add it on GitLab project.
- Prepare GitLab Token
- Create it on Gitlab project.
- Create a New App in ArgoCD
- Use the specified repo, path, and target revision.
- In ArgoCD:
- REPO URL:
https://oauth2:<your_token>.git
- PATH:
helm-nginx
- TARGET REVISION:
argo-nginx
(branch in GitLab)
- Use the specified repo, path, and target revision.
- Check Deployed Resources
- Verify that the NGINX service has been deployed correctly.
Check Auto Sync
-
Change NGINX Pod Image Tag
- Downgrade or upgrade the image tag in the Helm chart.
-
Check Resources
- Verify that the changes are automatically synced and applied to the NGINX pod.
Add a New Kubernetes Cluster
-
Update Kubeconfig
- Add a new cluster in
$HOME/.kube/config
:
ps: You can findclusters: ... - cluster: certificate-authority-data: ... server: https://10.1.5.201:6443 name: my-new-k8s
certificate-authority-data
andserver
info at 10.1.5.201 at path$HOME/.kube/config
.
- Add a new cluster in
-
Add a New User
- Include the user configuration:
ps: You can findusers: ... - name: kubernetes-admin_my_new_k8s user: client-certificate-data: ... client-key-data: ...
client-certificate-data
andclient-key-data
info at 10.1.5.201 at path$HOME/.kube/config
.
- Include the user configuration:
-
Add a New Context
- Add the context for the new cluster:
contexts: ... - context: cluster: my-new-k8s user: kubernetes-admin_my_new_k8s name: kubernetes-admin@cluster.my-new-k8s
- Add the context for the new cluster:
-
Verify the Contexts
- Run the following command to list contexts:
kubectl config get-contexts
- Run the following command to list contexts:
-
Create Directory in the ArgoCD Pod
- Execute these commands:
kubectl exec -it argocd-server-6b477b574d-bf4lz -n argocd bash mkdir -p /home/argocd/.kube exit
- Execute these commands:
-
Copy the Kubeconfig File
- Execute the following commands:
kubectl config view --raw > /tmp/config kubectl cp /tmp/config argocd-server-6b477b574d-bf4lz:/home/argocd/.kube/config -n argocd kubectl exec -it argocd-server-6b477b574d-bf4lz -n argocd -- cat /home/argocd/.kube/config
- Execute the following commands:
-
Add the Cluster to ArgoCD
- Use the following command:
argocd cluster add kubernetes-admin@cluster.my-new-k8s
- Use the following command:
Deploy a NGINX Service in Another Kubernetes Cluster
- Follow the same steps as “Deploy an NGINX Service In-Cluster”, but replace
in-cluster
withkubernetes-admin@cluster.my-new-k8s
.