HiveBrain v1.2.0
Get Started
← Back to all entries
snippetkubernetesMinor

How to deploy applications to k8s using bitbucket pipelines?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
pipelinesk8sbitbucketapplicationsdeployusinghow

Problem

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.

Solution

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.

Context

StackExchange DevOps Q#3536, answer score: 1

Revisions (0)

No revisions yet.