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.

1 Answer 1


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.

  • Could you add a bitbucket-pipeline.yml example?
    – 030
    Mar 5, 2018 at 20:35
  • You just need to setup the job as a pipeline with a jenkinsfile on bitbucket as a git SCM.
    – wolmi
    Mar 5, 2018 at 20:37
  • The authentication is part of the execution environment on the agent or master, depending on your deployment.
    – wolmi
    Mar 5, 2018 at 20:38
  • What authentication method do you use? I already have a bitbucket pipeline.
    – 030
    Mar 5, 2018 at 20:38
  • I tried to use Kubeconfig (See question)
    – 030
    Mar 5, 2018 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.