Score:0

How do you obtain $KUBE_CONFIG variable for a bitbucket deployment to a Kubernetes instance on Digital Ocean?

ni flag

So my company has been in the process of moving our backend application hosting from digital ocean droplets to a digital ocean kubernetes cluster.

However when following the bitbucket pipeline guide to update our pipelines for kubernetes (https://support.atlassian.com/bitbucket-cloud/docs/deploy-to-kubernetes/)

    - step:
    name: Deploy
    deployment: production
    script:
      - sed -i "s|{{image}}|$DOCKER_HUB_USERNAME/$APPLICATION_NAME:$BITBUCKET_COMMIT|g" deployment.yml
      - pipe: atlassian/kubectl-run:1.1.2
        variables:
          KUBE_CONFIG: $KUBE_CONFIG
          KUBECTL_COMMAND: 'apply'
          RESOURCE_PATH: 'deployment.yml'

There is a variable $KUBE_CONFIG which is not explained there or in other related resources i looked at.

Does anyone know how to find this variable? how to generate it? etc?, thanks even a basic overview of what it is would be helpful at this point.

Score:0
cn flag

Per the docs for the pipe you're using(see the Prerequisite section):

In order to configure the credentials in Pipelines, you will need to add the base64-encoded kubeconfig file as a Repository Variable. This is how you can obtain it: on Linux base64 -w 0 < ~/.kube/config and on Mac OS base64 < ~/.kube/config. Just copy the base64-encoded string from stdout and put in into the KUBE_CONFIG variable in your repository settings.

This pipe makes use of the kubeconfig file access method described here.

To outline this a little further, you'll need to:

  1. Retrieve your kubeconfig file. Do this by using the digitalocean web console. Selecting the overview tab for your k8s cluster, you'll see a big button to download config file. Save this file to your local environment.

  2. Convert the contents of that file to a base64-encoded string. From a terminal use the command base64 -w 0 <downloaded kube config file>. Copy the resulting string to your clipboard.

  3. Navigate to your bitbucket repository, select repository settings, and then select repository variables.

  4. In the name field enter KUBE_CONFIG and in the value field paste your base64-encoded config string from step 2. Select the secured box to make sure your config is obfuscated in your pipeline logs. (the name of this variable is arbitrary, fyi, it just needs to match your reference in the pipeline yaml)

This will create the repository variable $KUBE_CONFIG, containing the base64-encoded value of your kube config file, which your pipeline uses to populate the variable KUBE_CONFIG expected by the atlassian/kubectl-run pipe.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.