How to update Deployment in Minikube with Jenkins?

Viewed 549

I like to update my three Deployments on Minikube with Jenkins. So I configured a Shell command in a Jenkins-Job and put this in as command:

kubectl set image deployment/dev-lager dev-lager=volkanb/lagertest:latest
kubectl set image deployment/dev-lager dev-lager=volkanb/lagertest

kubectl set image deployment/test-lager test-lager=volkanb/lagertest:latest
kubectl set image deployment/test-lager test-lager=volkanb/lagertest

kubectl set image deployment/prod-lager prod-lager=volkanb/lagertest:latest
kubectl set image deployment/prod-lager prod-lager=volkanb/lagertest

When I type these commands manually it works. But configured as Shell commands in a Jenkins-Job it doesn't. What can I do to solve that problem?

1 Answers

In order to run kubernetes jobs from Jenkins you have to configure the credentials for cluster access first.

  • One great option is to follow the tutorial in Kubernetes Plugin Documentation. It has the step-by-step on how to configure the credentials.

  • Under section Kubernetes Cloud Configuration:

    In Jenkins settings click on add cloud, select Kubernetes and fill the information, like Name, Kubernetes URL, Kubernetes server certificate key, ...

    If Kubernetes URL is not set, the connection options will be autoconfigured from service account or kube config file.

    When running the Jenkins master outside of Kubernetes you will need to set the credential to secret text. The value of the credential will be the token of the service account you created for Jenkins in the cluster the agents will run on.

  • And in section Configuration on minikube:

    • Create and start minikube
    • The client certificate needs to be converted to PKCS, will need a password
    openssl pkcs12 -export -out ~/.minikube/minikube.pfx -inkey ~/.minikube/apiserver.key -in ~/.minikube/apiserver.crt -certfile ~/.minikube/ca.crt -passout pass:secret
    
    • Then validate that the certificates work:
    curl --cacert ~/.minikube/ca.crt --cert ~/.minikube/minikube.pfx:secret --cert-type P12 https://$(minikube ip):8443
    
    • Add a Jenkins credential of type certificate, upload it from ~/.minikube/minikube.pfx, password secret
    • Fill Kubernetes server certificate key with the contents of ~/.minikube/ca.crt

If you have any question after that, let me know in the comments or updating your question

Related