Before we install Microk8s, make sure you have kubernetes ready environment, since i have MacOS, i am using Microk8s here, similarly you can choose to install Depending on OS you are using here - Install Microk8s
and while running the command , you might face error similar to this
brew install ubuntu/microk8s/microk8s
let us use mutlipass as suggested
Using multipass, you can run ubuntu VM in MAC or Windows and it developed by canoical
and now lets install mutlipass and run microk8s like we run in ubuntu
keep settings as default and install
Alternately, you can also use AWS EC2 like we did it in our previous project - microk8s previous project
Now, lets use the commands provided in Doc to launch our instance
since we are going to install microk8s, kagent and kmcp in same VM, lets increase resources for VM
multipass launch --name microk8s --cpus 4 --memory 8G --disk 80G 24.04
once launched enter inside VM
multipass shell microk8s
sudo snap install microk8s --classic
sudo usermod -a -G microk8s ubuntu
mkdir ~/.kube
sudo microk8s kubectl config view --raw > ~/.kube/config
switch users for configuration change to take in effect
sudo su - root
sudo su - ubuntu
microk8s kubectl get all --all-namespaces
alias kubectl="microk8s kubectl"
Now, let us do a basic nginx image deployment
kubectl create ns nginx-demo
kubectl create deployment nginx --image=nginx:latest -n nginx-demo
check pod status
kubectl get pods -n nginx-demo
Now let us also create service to expose our application
kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort -n nginx-demo
check microk8s service
kubectl get svc -n nginx-demo
since service is exposed via nodeport inside VM, we need to get IP of VM
hostname -I
Try accessing application now at nodeport inside you local
http://VMIP:NodePort
Before we install kagent, lets get our openai apikey and you can see step by step process of how to get OpenAI API Key from this Blog - Fine Tuning
and Generate API Key
since our kubernetes setup is done, now lets go for installing kagent and see how it works
we can use official kagents documentation
paste the OpenAI API Key that generated
also install kubectl as kagent interacts mostly with kubectl
sudo snap install kubectl --classic
also install helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
curl https://raw.githubusercontent.com/kagent-dev/kagent/refs/heads/main/scripts/get-kagent | bash
let us check demo version which consists of few agents and mcp tools
since kagent profile takes lot of time to setup CRDs , we will use helm to install crds and kagent for faster setup
kagent install --profile demo
helm install kagent-crds oci://ghcr.io/kagent-dev/kagent/helm/kagent-crds \
--namespace kagent \
--version 0.7.7 \
--create-namespace
helm install kagent oci://ghcr.io/kagent-dev/kagent/helm/kagent \
--namespace kagent \
--version 0.7.7 \
--set providers.default=openAI \
--set providers.openAI.apiKey=$OPENAI_API_KEY
Since we are running inside VM, let us do a port-forward for our kagent dashboard
kubectl port-forward --address 0.0.0.0 -n kagent service/kagent-ui 8082:8080
Now access kagent dashboard with http://VMIP:8082
Now clikc on skip wizard to enter into dashboard
and you can see few agents already configured
and now click on any agent
and on the right, you can see tools like this agent can use
and for each question, it uses tools that is required for that use case, like when i asked how many pods are there in nginx-demo namespace, it has used k8s_get_resources tool
and when i asked it to increase pods to two resources, it did
let us create an agent , that is specifically only for scaling deployments
You are a Kubernetes deployment scaling agent.
You are only allowed to scale deployments up or down by changing replica counts.
Allowed actions:
- Get deployments
- List deployments
- Patch deployments/scale
- Update deployments/scale
Forbidden actions:
- Do not delete pods
- Do not delete deployments
- Do not create new workloads
- Do not read secrets
- Do not modify ConfigMaps
- Do not change images
- Do not restart deployments unless explicitly asked, and prefer scaling only
Before scaling, confirm:
1. Namespace
2. Deployment name
3. Current replicas
4. Requested replicas
After scaling, show:
1. Old replica count
2. New replica count
3. kubectl verification command
and you can check in terminal or refresh page in UI to check when agent is ready
and now since our new kagent dont have much of permissions, let us test this
and now i gave the task as it must, and it did as requested to scale deployment to 4 replicas
and verified
mutlipass stop microk8s
mutlipass delete microk8s










































Comments
Post a Comment