This post covers a lot (very quickly and reasonably easily);
It starts with using Kuberenets in Docker (KinD) to create a minimal but functional local Kubernetes Cluster.
Then, ArgoCD is setup and a sample app is deployed to the cluster.
Finally, k8sgpt is configured and a basic analysis of the cluster is run.
The main point of all of this was to try out k8sgpt in a safe and disposable environment.
Step 1: Install kind
First, ensure you have kind
installed.
KinD can be installed quickly and easily with just the following commands:
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
Check out this older post for more detail on KinD:
https://www.donaldsimpson.co.uk/2023/08/09/kind-local-kubernetes-with-docker-nodes-made-quick-and-easy/
Step 2: Create a kind
Cluster
Create a new kind
cluster:
kind create cluster --name argocd-cluster
Step 3: Install kubectl
Ensure you have kubectl
installed. You can install it using the following command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
Step 4: Install ArgoCD
- Create the
argocd
namespace:
kubectl create namespace argocd
- Install ArgoCD using the official manifests:
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Step 5: Access the ArgoCD API Server
- Forward the ArgoCD server port to localhost:
kubectl port-forward svc/argocd-server -n argocd 8080:443
- Retrieve the initial admin password:
kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d; echo
Step 6: Login to ArgoCD
- Open your browser and navigate to
https://localhost:8080
. - Login with the username
admin
and the password retrieved in the previous step.
Step 7: Install argocd
CLI
- Download the
argocd
CLI:
curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod +x argocd
sudo mv argocd /usr/local/bin/
- Login using the
argocd
CLI:
argocd login localhost:8080
- Set the admin password (optional):
argocd account update-password
Step 8: Deploy an Application with ArgoCD
- Create a new application:
argocd app create guestbook \
--repo https://github.com/argoproj/argocd-example-apps.git \
--path guestbook \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
- Sync the application:
argocd app sync guestbook
- Check the application status:
argocd app get guestbook
Step 9: Install K8sGPT
- Install K8sGPT CLI:
curl -Lo k8sgpt https://github.com/k8sgpt-ai/k8sgpt/releases/latest/download/k8sgpt-linux-amd64
chmod +x k8sgpt
sudo mv k8sgpt /usr/local/bin/
- Configure K8sGPT:
k8sgpt auth --kubeconfig ~/.kube/config
Step 10: Inspect the Cluster with K8sGPT
- Run K8sGPT to inspect the cluster:
k8sgpt analyze
Example Output and Possible Associated Actions
Example Output:
[INFO] Analyzing cluster…
[INFO] Found 3 issues in namespace default:
[WARNING] Pod guestbook-frontend-5d8d4f5d6f-abcde is in CrashLoopBackOff state
[WARNING] Service guestbook-frontend is not reachable
[INFO] Deployment guestbook-frontend has 1 unavailable replica
Associated Actions:
- Pod in CrashLoopBackOff State:
- Action: Check the logs of the pod to identify the cause of the crash.
- Command:
kubectl logs guestbook-frontend-5d8d4f5d6f-abcde -n default
- Possible Fix: Resolve any issues found in the logs, such as missing environment variables, incorrect configurations, or application errors.
- Service Not Reachable:
- Action: Verify the service configuration and ensure it is correctly pointing to the appropriate pods.
- Command:
kubectl describe svc guestbook-frontend -n default
- Possible Fix: Ensure the service selector matches the labels of the pods and that the pods are running and ready.
- Deployment with Unavailable Replica:
- Action: Check the deployment status and events to understand why the replica is unavailable.
- Command:
kubectl describe deployment guestbook-frontend -n default
- Possible Fix: Address any issues preventing the deployment from scaling, such as resource constraints or scheduling issues.
Conclusion
Ok, addmitedly that was a bit of a whirlwind, but if you followed it you have successfully deployed ArgoCD to a kind
cluster, deployed an application using ArgoCD to that new cluster, then inspected the cluster & app using K8sGPT.
The example output and associated actions from provide guidance on how to address common issues identified by K8sGPT.
This setup allows you to manage your applications and monitor the health of your Kubernetes cluster effectively, and being able to spin up a disposable cluster like this is handy for many reasons.
Discover more from Don's Blog
Subscribe to get the latest posts sent to your email.
There’a an earlier post here on setting up KinD, k8s dashboards and Lens etc:
http://dontemp.donwp.freemyip.com/2023/08/09/kind-local-kubernetes-with-docker-nodes-made-quick-and-easy/