user3646072
user3646072

Reputation: 153

Exporting nodejs app to Kubernetes with BitBucket

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.

Upvotes: 2

Views: 733

Answers (2)

Will
Will

Reputation: 4386

So I hit a similar issue to this trying to set the KUBECONFIG environment variable.

The issue happening here is some tool or cli command is trying to set KUBECONFIG to something other than a file.

In my case I was trying to be clever with kind and do this

KUBECONFIG=$(kind get kubeconfig --name kind-3)

the issue is that will set KUBECONFIG to the VALUE that you want inside of a kubeconfig FILE instead of a path to that file as it should be

https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable

so what you really want is

kind get kubeconfig --name kind-3 > local-kind-3-kubeconfig.yaml
export KUBECONFIG=$(pwd)/local-kind-3-kubeconfig.yaml

hopefully that saves someone (maybe me again ) in the future

Upvotes: 1

mpjs14
mpjs14

Reputation: 21

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.

Upvotes: 2

Related Questions