ArgoCD with k3d
Install ArgoCD on a k3d cluster with nginx deployment
ArgoCD with k3d
GitOps with ArgoCD
Pre-requisites
- Tools
- k3d
- git
- Understanding of below technologies:
- Git
- Kubernetes
- Containers
- GitOps concepts
Setup K3s Local Cluster
A. Create a cluster-config.yaml file:
1
2
3
4
5
6
cat <<EOF > cluster-config.yaml
apiVersion: k3d.io/v1alpha5
kind: Simple
servers: 1
agents: 2
EOF
B. Create a local K8 cluster
1
k3d cluster create argocd-cluster --config ./cluster-config.yaml
C. Verify if you are able to connect to the cluster.
1
kubectl get nodes
Installing ArgoCD
Create a new namesapce
1
kubectl create ns argocd
Deploy ArgoCD on Kuberntes
1
curl -o install.yaml https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
1
kubectl apply -n argocd -f install.yaml
OR
1
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Install ArgoCD CLI (Ref: https://argo-cd.readthedocs.io/en/stable/cli_installation/)
1
brew install argocd
Verify the argocd and argocd cli version
1
argocd version
1
argocd version --client
Expose the ArgoCD service on NodePort
1
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort"}}'
1
kubectl port-forward svc/argocd-server -n argocd 8080:443
Get the ArgoCD Username and Password
1
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo
Setup a Git Repo and create nginx deployment
Create a repository in GitHub
Clone the repository
1
git clone git@github.com:cloudutsukpilot/loony-argocd-repo.git
Create an nginx directory and nginx deployment files.
1
mkdir nginx_yaml_files && cd nginx_yaml_files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cat <<EOF > deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: nginx
labels:
app: nginxi
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cat <<EOF > service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx-service
namespace: nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: NodePort
EOF
- Push the new files to GitHub repository
1
git add .
1
git commit -m "Adding nginx files"
1
git push origin main
Sync the Repo in ArgoCD and Verify the Deployment
- Login into ArgoCD, and add the repository under Settings->Repositories using either https or ssh url of the git repository.
- Once connected, create a new app in ArgoCD under Applications and enter the required fields
- Application Name: simple-nginx-server
- Repository URL: Select from the List
- Path: nginx_yaml_files
- Cluster URL: https://kubernetes.default.svc
- Click on the
Create
button. Once created, sync the repo using theSYNC
button to deploy the nginx deployment and service on the kubernetes cluster. - Using port-forward on the nginx service and verify that it is accessible in the browser.
- Try changing the replicas in the git repo(push the changes) and manually sync the app in ArgoCD UI to view the changes replicated on the cluster.
- In ArgoCD, navigate to the application the enable the option for auto-sync, under
- Again try increasing/decreasing the replicas in the git repository and watch the changes automatically deployed to the k3d cluster.
CleanUp
Delete the k3d cluster
1
k3d cluster delete argocd-cluster
Remove the files
1
rm cluster-config.yaml
Delete the repository from github and local storage.
This post is licensed under CC BY 4.0 by the author.