ArgoCD
- Typical deployment into k8s
- GitOps
- Argo cd can be configure with Git repo for
- manifests
- helm
- kustomize
- To configure argo with git we can execute
- commands
- manifest files (yaml)
Argo CD Tutorial
Argo CD Tutorial with a Kubernetes Manifest Example in a Git Repository
Step 1: Set Up the Git Repository
-
Create a Git Repository:
Create a new Git repository on your preferred Git hosting service (e.g., GitHub, GitLab). -
Add a Sample Kubernetes Manifest:
Clone your repository and add a sample Kubernetes manifest. Below is an example of aguestbookapplication.
Directory Structure:
my-repo/
└── manifests/
├── deployment.yaml
├── service.yaml
deployment.yaml:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: guestbook
labels:
app: guestbook
spec:
replicas: 3
selector:
matchLabels:
app: guestbook
template:
metadata:
labels:
app: guestbook
spec:
containers:
- name: guestbook
image: redis:alpine
ports:
- containerPort: 6379
service.yaml:
yaml
apiVersion: v1
kind: Service
metadata:
name: guestbook
spec:
selector:
app: guestbook
ports:
- protocol: TCP
port: 80
targetPort: 6379
type: ClusterIP
- Push the Files to Git:
bash
git add .
git commit -m "Add guestbook Kubernetes manifests"
git push origin main
Step 2: Install Argo CD
Follow the installation steps provided in the main tutorial:
1. Create the namespace:
bash
kubectl create namespace argocd
2. Install Argo CD:
bash
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
3. Port-forward the service to access the UI:
bash
kubectl port-forward svc/argocd-server -n argocd 8080:443
Step 3: Create the Argo CD Application
-
Login to Argo CD:
Retrieve the admin password:
bash
kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d
Login via the CLI:
bash
argocd login localhost:8080 -
Add Your Git Repository to Argo CD:
Replace<GIT_REPO_URL>with the URL of your repository:
bash
argocd repo add <GIT_REPO_URL> -
Create an Argo CD Application:
Run the following command to create an application in Argo CD:
bash
argocd app create guestbook \
--repo <GIT_REPO_URL> \
--path manifests \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
Example:
bash
argocd app create guestbook \
--repo https://github.com/your-username/my-repo.git \
--path manifests \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
Step 4: Sync the Application
-
Sync the Application via CLI:
bash
argocd app sync guestbook - Sync the Application via UI:
- Access the Argo CD web UI at
https://localhost:8080. - Login using the admin credentials.
- Click on the
guestbookapplication. - Click the “Sync” button to deploy the application.
-
Verify the Deployment:
Check the resources in the Kubernetes cluster:
bash
kubectl get all -n default
Step 5: Monitor and Manage the Application
-
Check Application Status:
bash
argocd app get guestbook -
View Logs:
To view logs of a specific pod:
bash
kubectl logs <POD_NAME> -n default - Update the Application:
- Modify the manifests in the Git repository.
- Commit and push the changes.
-
Argo CD will detect the changes and show the application as
OutOfSync. -
Sync Again:
bash
argocd app sync guestbook
Step 6: Enable Automatic Sync (Optional)
To enable auto-sync for the guestbook application:
argocd app set guestbook --sync-policy automated
Step 7: Clean Up
To delete the application and resources:
argocd app delete guestbook
To uninstall Argo CD:
kubectl delete namespace argocd
Argo CD Tutorial with Helm Chart Deployment
Step 1: Set Up the Git Repository with Helm Charts
- Create a Git Repository:
- Create a new repository to store your Helm chart or use an existing one.
- Add a Sample Helm Chart:
- You can create a Helm chart using the
helm createcommand or download an existing one.
Example directory structure for a Helm chart:
my-repo/
└── helm/
└── guestbook/
├── Chart.yaml
├── values.yaml
├── templates/
├── deployment.yaml
├── service.yaml
Chart.yaml:
yaml
apiVersion: v2
name: guestbook
description: A sample Helm chart for a Kubernetes application
version: 1.0.0
appVersion: 1.0.0
values.yaml:
yaml
replicas: 3
image:
repository: redis
tag: alpine
service:
type: ClusterIP
port: 6379
templates/deployment.yaml:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
labels:
app: {{ .Chart.Name }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- containerPort: {{ .Values.service.port }}
templates/service.yaml:
yaml
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}
spec:
type: {{ .Values.service.type }}
ports:
- port: 80
targetPort: {{ .Values.service.port }}
selector:
app: {{ .Chart.Name }}
- Push the Chart to Git:
bash
git add .
git commit -m "Add Helm chart for guestbook application"
git push origin main
Step 2: Install Argo CD
Follow the installation steps as described in the Argo CD installation tutorial. Ensure Argo CD is installed and running in your Kubernetes cluster.
Step 3: Deploy the Helm Chart Using Argo CD
-
Add Your Git Repository to Argo CD:
bash
argocd repo add <GIT_REPO_URL> -
Create an Argo CD Application for the Helm Chart:
Replace<GIT_REPO_URL>and<APP_NAME>with your repository URL and application name.
bash
argocd app create guestbook-helm \
--repo <GIT_REPO_URL> \
--path helm/guestbook \
--dest-server https://kubernetes.default.svc \
--dest-namespace default \
--helm-set replicas=3 \
--helm-set image.repository=redis \
--helm-set image.tag=alpine
Example:
bash
argocd app create guestbook-helm \
--repo https://github.com/your-username/my-repo.git \
--path helm/guestbook \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
- Sync the Application:
bash
argocd app sync guestbook-helm
Step 4: Use Helm Repository (Optional)
If you want to deploy a chart directly from a Helm repository (e.g., Bitnami charts), follow these steps:
-
Add the Helm Repository:
bash
argocd repo add https://charts.bitnami.com/bitnami --type helm -
Create an Application Using a Helm Chart:
bash
argocd app create guestbook-helm \
--repo https://charts.bitnami.com/bitnami \
--helm-chart redis \
--revision 17.4.0 \
--dest-server https://kubernetes.default.svc \
--dest-namespace default \
--helm-set replicaCount=3 -
Sync the Application:
bash
argocd app sync guestbook-helm
Step 5: Monitor and Manage the Application
-
Check Application Status:
bash
argocd app get guestbook-helm - View Application Details in the Web UI:
- Access the Argo CD web UI at
https://localhost:8080. -
Navigate to the
guestbook-helmapplication to see deployment details, status, and logs. -
Update the Helm Values:
To update Helm values (e.g., change the number of replicas):
bash
argocd app set guestbook-helm --helm-set replicas=5
argocd app sync guestbook-helm -
Rollback to a Previous Version:
bash
argocd app rollback guestbook-helm <REVISION_NUMBER>
Step 6: Enable Auto-Sync for Helm Applications
Enable auto-sync for the guestbook-helm application:
argocd app set guestbook-helm --sync-policy automated
Step 7: Clean Up
To delete the Helm application and resources:
argocd app delete guestbook-helm
To uninstall Argo CD:
kubectl delete namespace argocd
