<p>You need to separate your daily authentication method of the CD authentication.</p>

<p>You should start understanding the different methods that K8S offers <a href="https://kubernetes.io/docs/admin/authentication/" rel="nofollow noreferrer">https://kubernetes.io/docs/admin/authentication/</a></p>

<p>On the other hand if you use some cloud solution like GCP you can benefit of the service account that the platform puts in all your instances, setting the right permissions to a service account allow you to to controll any cluster inside your project like in your local machine.</p>

CC BY-SA 3.0
2018-03-05T20:35:06.403Z
Could you add a bitbucket-pipeline.yml example?
030
CC BY-SA 3.0
2018-03-05T20:37:32.527Z
You just need to setup the job as a pipeline with a jenkinsfile on bitbucket as a git SCM.
wolmi
CC BY-SA 3.0
2018-03-05T20:38:11.333Z
The authentication is part of the execution environment on the agent or master, depending on your deployment.
wolmi
CC BY-SA 3.0
2018-03-05T20:38:23.270Z
What authentication method do you use? I already have a bitbucket pipeline.
030
CC BY-SA 3.0
2018-03-05T20:39:02.833Z
I tried to use Kubeconfig (See question)
030
CC BY-SA 3.0
2018-03-05T20:40:54.600Z
I use simply a service account inside a Google Cloud Engine instance with permission to access my K8S cluster. With that Jenkins only need the namespace to execute your pipeline as a shell steps
wolmi
CC BY-SA 3.0
2018-04-27T16:04:19.920Z
If you could add some steps how to achieve this then that would really help
030
CC BY-SA 4.0
2018-05-22T10:17:08.287Z
I use github token authentication, but maybe this answer to connect jenkins with a bitbuket repository can help you. https://stackoverflow.com/questions/20203565/connecting-to-bitbucket-repository-from-jenkins-server
wolmi
CC BY-SA 3.0
2018-03-05T20:24:28.700Z
2018-03-05T20:24:28.700Z
wolmi
<p>The aim is to implement Continuous Deployment (CD) to a k8s cluster.</p>

<p>It works to deploy a Nginx image to the k8s.</p>

<p><a href="https://github.com/kubernetes/kubernetes/blob/master/examples/simple-nginx.md" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/master/examples/simple-nginx.md</a>
<code>
kubectl run my-nginx --image=nginx --replicas=2 --port=80
</code></p>

<p>When the same command is run in a CD tool then it complains that it cannot find the cluster. Off course it is possible to copy the <code>~/.kube/config</code>, but is that recommended?</p>

<p>When the Kubeconfig is stored in a variable and kubectl is run by bitbucketpipelines then the following error is thrown:</p>

<pre><code>error: Error loading config file "/root/.kube/config": yaml: mapping values are not allowed in this context
</code></pre>

<p>Inspecting the files turns out that the whole file consists of one line instead of multiple. </p>

<kubernetes><bitbucket-pipelines>
How to deploy applications to k8s using bitbucket pipelines?
030
# How to deploy applications to k8s using bitbucket pipelines?

(Asked by: username_0 on 2018-03-03)

The aim is to implement Continuous Deployment (CD) to a k8s cluster.
It works to deploy a Nginx image to the k8s.
https://github.com/kubernetes/kubernetes/blob/master/examples/simple-nginx.md

kubectl run my-nginx --image=nginx --replicas=2 --port=80

When the same command is run in a CD tool then it complains that it cannot find the cluster. Off course it is possible to copy the ~/.kube/config, but is that recommended?
When the Kubeconfig is stored in a variable and kubectl is run by bitbucketpipelines then the following error is thrown:
error: Error loading config file "/root/.kube/config": yaml: mapping values are not allowed in this context

Inspecting the files turns out that the whole file consists of one line instead of multiple.

**Tags:** kubernetes, bitbucket-pipelines


---

## 1 answers

### Answer by username_1 on 2018-03-05. Score: 1 | Accepted answer

You need to separate your daily authentication method of the CD authentication.

You should start understanding the different methods that K8S offers <https://kubernetes.io/docs/admin/authentication/>

On the other hand if you use some cloud solution like GCP you can benefit of the service account that the platform puts in all your instances, setting the right permissions to a service account allow you to to controll any cluster inside your project like in your local machine.

> **Comments:**
> **username_0**: Could you add a bitbucket-pipeline.yml example?  
> **username_1**: You just need to setup the job as a pipeline with a jenkinsfile on bitbucket as a git SCM.  
> **username_1**: The authentication is part of the execution environment on the agent or master, depending on your deployment.  
> **username_0**: What authentication method do you use? I already have a bitbucket pipeline.  
> **username_0**: I tried to use Kubeconfig (See question)  
> **username_1**: I use simply a service account inside a Google Cloud Engine instance with permission to access my K8S cluster. With that Jenkins only need the namespace to execute your pipeline as a shell steps  
> **username_0**: If you could add some steps how to achieve this then that would really help  
> **username_1**: I use github token authentication, but maybe this answer to connect jenkins with a bitbuket repository can help you. https://stackoverflow.com/questions/20203565/connecting-to-bitbucket-repository-from-jenkins-server  

---

