DevOps Classroom notes 30/Nov/2024

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

  1. Create a Git Repository:
    Create a new Git repository on your preferred Git hosting service (e.g., GitHub, GitLab).
  2. Add a Sample Kubernetes Manifest:
    Clone your repository and add a sample Kubernetes manifest. Below is an example of a guestbook application.

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

  1. 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

  1. 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
  2. Add Your Git Repository to Argo CD:
    Replace <GIT_REPO_URL> with the URL of your repository:
    bash
    argocd repo add <GIT_REPO_URL>
  3. 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

  1. Sync the Application via CLI:
    bash
    argocd app sync guestbook
  2. Sync the Application via UI:
  3. Access the Argo CD web UI at https://localhost:8080.
  4. Login using the admin credentials.
  5. Click on the guestbook application.
  6. Click the “Sync” button to deploy the application.
  7. Verify the Deployment:
    Check the resources in the Kubernetes cluster:
    bash
    kubectl get all -n default

Step 5: Monitor and Manage the Application

  1. Check Application Status:
    bash
    argocd app get guestbook
  2. View Logs:
    To view logs of a specific pod:
    bash
    kubectl logs <POD_NAME> -n default
  3. Update the Application:
  4. Modify the manifests in the Git repository.
  5. Commit and push the changes.
  6. Argo CD will detect the changes and show the application as OutOfSync.
  7. 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

  1. Create a Git Repository:
  2. Create a new repository to store your Helm chart or use an existing one.
  3. Add a Sample Helm Chart:
  4. You can create a Helm chart using the helm create command 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 }}

  1. 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

  1. Add Your Git Repository to Argo CD:
    bash
    argocd repo add <GIT_REPO_URL>
  2. 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

  1. 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:

  1. Add the Helm Repository:
    bash
    argocd repo add https://charts.bitnami.com/bitnami --type helm
  2. 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
  3. Sync the Application:
    bash
    argocd app sync guestbook-helm

Step 5: Monitor and Manage the Application

  1. Check Application Status:
    bash
    argocd app get guestbook-helm
  2. View Application Details in the Web UI:
  3. Access the Argo CD web UI at https://localhost:8080.
  4. Navigate to the guestbook-helm application to see deployment details, status, and logs.
  5. 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
  6. 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

Well known k8s issues and how to resolve them

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Plugin for Social Media by Acurax Wordpress Design Studio

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%