<p>I'm new to docker/kubernetes/dev ops in general and I was following a course that used <code>Travis</code> with <code>Github</code>, however I use <code>BitBucket</code> so I'm trying to implement a CI deployment to GKE with <code>CircleCI</code>.</p>

<p>Most of the tasks are working just fine but I'm reaching an error when it comes to <code>kubectl</code> (especifically on the <code>deploy.sh</code> script). Here's the error I'm getting:</p>

<pre><code>unable to recognize "k8s/client-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/database-persistent-volume-claim.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/ingress-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/postgres-cluster-ip-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/postgres-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/redis-cluster-ip-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/redis-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/server-cluster-ip-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/server-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/worker-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
</code></pre>

<p>I've managed to get this far tackling through problems, however I'm lost on this one so any help is appreciated.</p>

<p>Here's the <code>config.yml</code> for CircleCI (on <code>MyUser</code> I'm actually using my docker user, not an env or anything, it's simply to not disclose it):</p>

<pre><code>version: 2
jobs:
  build:
    docker:
      - image: node

    working_directory: ~/app

    steps:
      - checkout
      - setup_remote_docker

      - run:
          name: Install Docker Client
          command: |
            set -x
            VER="18.09.2"
            curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv /tmp/docker/* /usr/bin

      - run:
          name: Build Client Docker Image
          command: docker build -t MY_USER/multi-docker-react -f ./client/Dockerfile.dev ./client

      - run:
          name: Run Tests
          command: docker run -e CI=true MY_USER/multi-docker-react npm run test -- --coverage

  deploy:
    working_directory: ~/app
    # Docker environment where we gonna run our build deployment scripts 
    docker:
    - image: google/cloud-sdk

    steps:
    - checkout
    - setup_remote_docker:
        docker_layer_caching: true

    # Set up Env
    - run:
        name: Setup Environment Variables
        command: |
          echo 'export GIT_SHA="$CIRCLE_SHA1"' &gt;&gt; $BASH_ENV
          echo 'export CLOUDSDK_CORE_DISABLE_PROMPTS=1' &gt;&gt; $BASH_ENV

          # Log in to docker CLI
    - run:
        name: Log in to Docker Hub
        command: |
          echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin

    # !!! This installs gcloud !!!
    - run:
        name: Installing GCL
        working_directory: /
        command: |
          echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
          gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
          gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}

    # !!! This runs a deployment
    - run:
        name: Deploying
        command: bash ./deploy.sh

workflows:
  version: 2
  build:
    jobs:
    - deploy:
        filters:
          branches:
            only:
            - master
</code></pre>

<p>Here's the <code>deploy.sh</code>:</p>

<pre><code>docker build -t MY_USER/multi-docker-client:latest -t MY_USER/multi-docker-client:$GIT_SHA -f ./client/Dockerfile ./client
docker build -t MY_USER/multi-docker-server:latest -t MY_USER/multi-docker-server:$GIT_SHA -f ./server/Dockerfile ./server
docker build -t MY_USER/multi-docker-worker:latest -t MY_USER/multi-docker-worker:$GIT_SHA -f ./worker/Dockerfile ./worker
docker push MY_USER/multi-docker-client:latest
docker push MY_USER/multi-docker-server:latest
docker push MY_USER/multi-docker-worker:latest
docker push MY_USER/multi-docker-client:$GIT_SHA
docker push MY_USER/multi-docker-server:$GIT_SHA
docker push MY_USER/multi-docker-worker:$GIT_SHA
kubectl apply -f k8s
kubectl set image deployments/client-deployment client=MY_USER/multi-docker-client:$GIT_SHA
kubectl set image deployments/server-deployment server=MY_USER/multi-docker-server:$GIT_SHA
kubectl set image deployments/worker-deployment worker=MY_USER/multi-docker-worker:$GIT_SHA
</code></pre>

<p>And here's my project structure:</p>

<p><a href="https://i.stack.imgur.com/b3vnc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b3vnc.png" alt="enter image description here"></a></p>

<p>So turns out I was only missing the next command:</p>

<p><code>gcloud --quiet container clusters get-credentials multi-cluster</code></p>

<p>As part of this task:</p>

<pre><code>    # !!! This installs gcloud !!!
    - run:
        name: Installing GCL
        working_directory: /
        command: |
          echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
          gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
          gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
          gcloud --quiet container clusters get-credentials multi-cluster
</code></pre>

<p>Shout out to @DazWilkin for shedding a light</p>
