docker – Access kubectl commands within my jenkins container
I have a Jenkins container running in docker compose.
Inside my jenkins container I want to access kubectl, so far this was part of my docker-compose.yaml
- /usr/local/bin/kubectl:/usr/local/bin/kubectl
- ~/.kube/config:/var/jenkins_home/.kube/config
But when I do the command kubectl version inside my container it gives the following error
Client Version: v1.30.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Error from server (Forbidden):
Authentication required
Searching, i found i needed to create a serviceaccount which i did, and also created a secret manually and use the command
kubectl patch sa jenkins-sa -p '{"secrets": [{"name": "jenkins-secret"}]}'
But i don't know how to link that to my docker-compose.yaml.
Also, i read about modifying the ~/.kube/config but i don't know what I'm supposed to add there.
Read more here: Source link
