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
This is expected as sierra is deprecated and there was no replacement, here is supporting github issue
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
command
multipass launch --name microk8s --cpus 4 --memory 8G --disk 80G 24.04
once launched enter inside VM
command: multipass shell microk8s
and now let us setup our kubernetes environment, the way we did for previous project and follow steps from here -
microk8s deployment
command: sudo snap install microk8s --classic
command: 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
command:
sudo su - root
sudo su - ubuntu
command:
microk8s kubectl get all --all-namespaces
command: alias kubectl="microk8s kubectl"
Now, let us do a basic nginx image deployment
kubectl create ns nginx-demo
command: kubectl create deployment nginx --image=nginx:latest -n nginx-demo
check pod status
command: kubectl get pods -n nginx-demo
Now let us also create service to expose our application
command: kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort -n nginx-demo
check microk8s service
command: kubectl get svc -n nginx-demo
since service is exposed via nodeport inside VM, we need to get IP of VM
command: 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
paste the OpenAI API Key that generated
also install kubectl as kagent interacts mostly with kubectl
command: sudo snap install kubectl --classic
also install helm
command
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
command:
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
Alternate install
helm install kagent-crds oci://ghcr.io/kagent-dev/kagent/helm/kagent-crds \
--namespace kagent \
--version 0.7.7 \
--create-namespace
Now let us install kagent
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
and since it has already tools added, we will use same tool that is being used and Agent instructions must be clear
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
Comments
Post a Comment