Skip to content

klovercloud-ci-cd/kcd-workshop-gitops-argocd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Workshop On Deploy Application in Kubernetes Using GitOps & ArgoCD

Hello everyone, welcome to the workshop on "Deploy Application in Kubernetes Using GitOps & ArgoCD".

In this workshop we will be working on the following tasks.

Task 1: Deploy an application in your k8 cluster using GitOps and ArgoCD.

Task 2: Deploy a helm chart in your k8 cluster using GitOps and ArgoCD.

Along with these tasks, we will be seeing different functionalities, scopes and best practices of ArgoCD and GitOps.

Pre-Requisite

To follow along with this workshop, you will require a basic understanding of the followings:

  1. Basic knowledge of Kubernetes and its different resources and components (such as: Deployments, Pods, Services etc).
  2. Basic understanding of Helm.
  3. Basic idea of yaml.
  4. Kubernetes manifests file.
  5. Basic usage of Kubectl.
  6. Basic understanding of Docker.

If you full-fill all the requirements, then you are good to go.

Setup Environment

Let's start with setting our environment. To start working with ArgoCD.

For this workshop we will be working on our local machine. We'll setup Kubernetes cluster using Kind deploy ArgoCD on our machine.

For production environment, you will need to setup Kubernetes production cluster. ArgoCD setup is same for any environment.

So, before proceeding further, let's setup the environment. To setup environment for the workshop, your local machine should have the following tools pre installed.

Create a new Kubernetes cluster

We will use kind to create a new cluster on your local machine. Run the following command,

kind create cluster --name kcd-cluster-one

You can check the cluster context and use it.

kubectl config get-contexts

kubectl config use-context kind-kcd-cluster-one

Install ArgoCD

For more info click here

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Wait until all the required pods are running.

Get ArgoCD Admin Password

kubectl get secrets/argocd-initial-admin-secret -n argocd --template={{.data.password}} | base64 -d

ArgoCD Dashboard

Since we are working on local machine, we will be exposing the Argocd dashboard through port forwarding. In production, you can use kubernetes Ingress or LoadBalancer to expose ArgoCD Web UI.

Run the following command to port-forward the argocd server. You can expose it to any port.

kubectl port-forward -n argocd svc/argocd-server 8080:80

Login with the username "admin" and password admin password from secret.

Install ArgoCD CLI

Install ArgoCD Cli tool to connect argocd from terminal. The installation guidelines for each operating system are documented here

You can found all the command reference of ArgoCD Cli from here.

Login to ArgoCD from CLI

Since we are running our argocd in local machine using port forwarding, to connect with the argocd we need to provide the localmachine IP, port and admin credentials. In production, you will need to provide the exposed ArgoCD URL for login along with the admin credentials of ArgoCD.

Run the following command in your machine. Make sure the port-forward is running, before executing the command. To connect with the production ArgoCD, replace the server host and port with your ArgoCD URL along with the admin username and password.

argocd login localhost:8080 --insecure \
--username admin \
--password $(kubectl get secrets/argocd-initial-admin-secret -n argocd --template={{.data.password}} | base64 -d)

Check if its successfully connected or not.

argocd cluster list

Let's Get Started

Task 1 - Deploy Application

Create a new application from ArgoCD UI and deploy the application. Check here for the application descriptors.

We are going to deploy kcd-demo-app in ArgoCD.

REPO URL: https://github.com/shaekhhasanshoron/kcd-demo-app
PATH: kubernetes/manifests
REVISION: HEAD

Task 2 - Automated vs Manual Sync

In manual sync we need to manually sync the updates or commits. ArgoCD supports both of the sync system. However, If you consider GitOps principles, application it needs to automated.

Task 3 - Update manifests

We will update the manifests to check the output. We will update it from Git also from Cluster it-self. We will update the configurations inside the server directly and we will see that ArgoCD will alter that change and move it to the desired state.

Task 4 - Redeploy and Rollback to Previous Deployment

Let us see how the re-deploy and rollback feature.

Task 5 - Create a new Project

We will create a new project and add another application to that newly created project.

Task 6 - Adding Roles to Project

We will set different roles to project.

Task 7 - Add a Git repositories

We will add a git repo in ArgoCD git repo list. We will add kcd-notify-app repo. Run the following command. Here, you will attach token instead of password.

argocd repo get https://github.com/shaekhhasanshoron/kcd-notify-app

Now check the repo list.

argocd repo list

Task 8 - Create a new user

You need to update the argocd-cm configmap and add user data.

kubectl edit cm -n argocd argocd-cm

Add the following code under data and save it.

  accounts.shoron: apiKey, login
  accounts.shoron.enabled: "true"

Check User list

argocd account list

Task 9 - Update the user password

Since initially newly created your will not have any password, we have to add the password for the new user.

argocd account update-password \
  --account shoron \
  --current-password $(kubectl get secrets/argocd-initial-admin-secret -n argocd --template={{.data.password}} | base64 -d) \
  --new-password Hello@123

Task 10 - Provide Permission: RBAC

By default, new user does not have any permission. You need to provide the permissions to user. You need to add user permission in a argocd-rbac-cm configmap.

kubectl edit cm -n argocd argocd-rbac-cm

Here is the following format to update permission for user.

p, <role/user/group>, <resource>, <action>, <appproject>/<object>, <allow/deny>

Now edit argocd-rbac-cm configmap and add the following code under data and save it.

  policy.csv: |
    p, shoron, applications, *, default/*, allow
  policy.default: read:readonly

You can add several permissions to it.

  policy.csv: |
    p, shoron, applications, *, default/*, allow
    p, shoron, clusters, get, *, allow
    p, shoron, projects, get, default, allow
    p, shoron, repositories, *, *, allow

Task 11 - Disable user

You need to update the argocd-cm configmap and add user data.

kubectl edit cm -n argocd argocd-cm

Task 12 - Deploy a new Application in Project

Create a new application from ArgoCD UI and deploy the application. Check here for the application descriptors.

We are going to deploy kcd-notify-app in ArgoCD.

REPO URL: https://github.com/shaekhhasanshoron/kcd-notify-app
PATH: kubernetes/manifests
REVISION: HEAD

Here we will use ArgoCD CLI to deploy.

argocd app create argocd/applications/kcd-notify.yaml

Task 13 - Hooks

Hooks can be used while synchronizing your application with ArgoCD. For details click here

Here just to show how does it work, we will create a new file under the manifest folder and add the following code. We are just notify a message to notify service api.

apiVersion: batch/v1
kind: Job
metadata:
  generateName: kcd-notify-config-
  annotations:
    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/hook-delete-policy: HookSucceeded
    argocd.argoproj.io/sync-wave: "1"
spec:
  template:
    spec:
      containers:
        - name: kcd-notify
          image: curlimages/curl
          command:
            - "curl"
            - "-X"
            - "POST"
            - "http://kcd-notify.demo:8080/api/notify?message=Synched"
      restartPolicy: Never
  backoffLimit: 2

Task 14 - Removing Application

We will remove the application.

argocd app delete <app name>

Task 15 - Create a new Helm Application from Public Helm Repo

We will create a new application from a public helm repository. We will deploy WildFly app server from https://charts.bitnami.com/bitnami helm repo. We will update parameters and deploy the applications.

REPO URL : https://charts.bitnami.com/bitnami
CHART NAME: wildfly
VERSION: 19.1.1

Task 16 - Create a Helm Application from Git Repo with custom Values

We have already extracted the WildFly app server chart from https://charts.bitnami.com/bitnami public repo. View the app repository, kcd-wildfly.

REPO URL: https://github.com/shaekhhasanshoron/kcd-wildfly
PATH: helm/wildfly
REVISION: HEAD

Task 17 - Take Backup and Restore

We will take a backup of the current state. Run the following command.

argocd -n argocd admin export > backup.yaml

We will update some changes and then import the backup file and check what happens.

argocd -n argocd admin import - < backup.yaml

Thank you

Please visit Klovercloud.com.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published