Exporting nodejs app to Kubernetes with BitBucket

11/21/2019

I have problem with setting bitbucket pipeline for export to Kubernetes. I succesfully run kubernetes onprem, public by publicIP. I have created deployment, services and ingress. Everything working nicely, this is my last stop ... :(

My pipeline:

#enabling docker
options:
  docker: true    
pipelines:
      branches:
        develop:
        - step:
            name: Build app for Develop purposes
            image: node:12.13.0
            caches:
              - node
            script:
              - pwd
              - ls -al
              - npm install  
              # Run our Tests
              # - npm test
              # Package App for Production
              - npm run build:dev
            artifacts:
              - build/**
        - step:
           name: Build Docker Image
           script:
            - export IMAGE_NAME=rurrobotics/ilog-develop:$BITBUCKET_COMMIT
            - docker build -t $IMAGE_NAME .
              # authenticate with the Docker Hub registry
            - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
              # push the new Docker image to the Docker registry
            - docker push $IMAGE_NAME
        - step:
           name: Deploy to Kubernetes
           image: atlassian/pipelines-kubectl
           deployment: test
           script: 
            - export IMAGE_NAME=rurrobotics/ilog-develop:$BITBUCKET_COMMIT
            - echo $KUBE_TOKEN | base64 -d > ./kube_token
            - echo $KUBE_CA | base64 -d > ./kube_ca
            - kubectl config set-cluster kubernetes --server="https://my-public-IP:6443" --certificate-authority="$(pwd)/kube_ca"
            - kubectl config set-credentials bitbucket --token="$(cat ./kube_token)"
            - kubectl config set-context development --cluster=kubernetes --user=bitbucket
            - kubectl config use-context development
            - kubectl --namespace=dev set image deployment/ilog-app ilog-app=$IMAGE_NAME

Everything works fine until bitbucket says:

+ kubectl config set-cluster kubernetes --server="https://my-public-ip" --certificate-authority="$(pwd)/kube_ca"
error loading config file " LS0tLS1CRUdJTiBDR...bz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=     server: file name too long
error loading config file " LS0tLS1CRUdJTiBDR... VEUtLS0tLQo=     client-key-data: file name too long
error loading config file " LS0tLS1Ck1N0RuT.....VktLS0tLQo=: file name too long

I tried multiple tutorials, nothing helps me.

-- user3646072
bitbucket
bitbucket-pipelines
kubernetes

1 Answer

3/2/2020

I had the exact same issue, and spent waay to long troubleshooting. So for anybody coming here later:

For me the problem was a repository value I added in the pipeline settings earlier called $KUBECONFIG.

After I deleted this value everything worked as it should.

-- mpjs14
Source: StackOverflow