How do i connect docker pipeline on jenkins to kubernetes cluster

HOW TO -️ October 18, 2021

I am trying to setup a pipeline on jenkins that uses docker containers to execute tasks like for example deploy an helm charts using a docker image with helm

here is what my Jenkinsfile looks like

ERROR Rendering Code Block

but it fails at the helm ls line because it can not connect to the kubernetes cluster. How do i connect this pipeline to use the Kubernetes configuration(kubeconfig) i have setup

here is error am getting

ERROR Rendering Code Block

I could not find any documentation on how to connect docker pipeline to connect to the kubernetes cluster What do i add to the Jenkinsfile to be able to connect?

UPDATE

i also tried this

ERROR Rendering Code Block

and got this error

ERROR Rendering Code Block

I could not find any documentation on how to connect docker pipeline to connect to the kubernetes cluster

What do i add to the Jenkinsfile to be able to connect?

so seems the docker container is unable to resolve the dns of the kubernetes cluster

how do i resolve this?

Answer

Where do you have the kubeconfig? as credentials in jenkins..i am able to use it with *kubernetesDeploy* with reference of the crdentials as kubeconfigId here is link to the plugin https://wiki.jenkins.io/display/JENKINS/Kubernetes+Continuous+Deploy+Plugin issue now is how do i reference that in docker pipeline in jenkinsfile so when i run something like helm or kubectl it is able to use that kubeconfig credential to connect to the kubernetes cluster

Initializing...