How to define kubernetes manifest for GCP-GKE orb?

I am trying to deploy an application to a Google Kubernetes Engine cluster. The deployment setup will differ by branch. For example the master will deploy to prod while several development branches will not. The deployment further contains different network setting such as Ingress and service configurations.

I have not found any documents describing how to set the manifest files during deployment. Can someone perhaps give me a good pointer, or is it down to a custom command?

I have been moving some pipelines to GKE recently and found documentation somewhat lacking at However, doc clone failed so to answer my own question, please find below a suggested config.yml (incl. some comments) that works for me based on this CircleCi Blog post.

Note that I had to apply 6 changes, indicated below, to the proposed config.yml in the article due to updates in gcloud shell, nodejs, and the commands available in the referenced orbs. This is beside the illustration on how to include the kubernetes manifest files (using a run/command). Perhaps a person luckier with the doc repo cloning can add this for other people to find more easily.

An existing project set up with GKE and APIs enabled, e.g. mygkeproject is required and you would need to replace below with your project name/id. Also, you must insert your own compute zone as required and do check that the GCR link is referencing the proper location.

version: 2.1 # using 2.1 provides access to orbs and other features
  # CHANGE 1/6: @1.1.1 not 1.0.1 as 1.0.1 contains bad key servers for node
  node: circleci/node@1.1.1 # jest/unit testing orb ideally 2.0.2 but 1.1.1 is the oldest still working
  gcr: circleci/gcp-gcr@0.0.2 # Google registry orb for GKE deploy target
  gke: circleci/gcp-gke@0.2.0 # Google GKE orb for GKE deploy target # CHANGE 5/6 must be 0.2.0 to allow for separate deployment/cluster definition
    description: Build NPM image and push to Google Container Registry
    # machine option runs your jobs in a dedicated, ephemeral VM that has the following specifications:
    machine: true
      - checkout
      # Install node
      - node/install-node # CHANGE 2/6: "install-node" for node orb 1.1.1 not "install"
      # Install npm
      - node/install-npm
      # Download and cache dependencies
      - node/with-cache:
            - run:
                name: Install node application dependencies
                command: npm install
            - run: # CHANEG 3/5: actually run an application build from source that you can copy in the Dockerfile
                name: Build the node application
                command: npm run build
          # Save cache
          cache-key: package.json
          # Ignore non-checksum cache hits
          use-strict-cache: true
      # CHANGE 4/5: merge node build and image build/push
      - gcr/gcr-auth
      - gcr/build-image:
          image: mygkeproject-circle-ci-gke
          tag: "v2" #Change version number e.g to 'v3' when updating application
      - gcr/push-image:
          image: mygkeproject-circle-ci-gke
          tag: "v2" #Change version number e.g to 'v3' when updating application
      # Install `gcloud` and `kubectl` if not already installed.
      - gke/install
      # Initialize the `gcloud` CLI.
      - gke/init
      # CHANGE 6/6: Load Kubernetes manifests
      - run:
          name: Associate target cluster context
          command: gcloud container clusters get-credentials mygkeproject-gke-cluster --zone us-central1-c
      - run:
          name: Load Kubernetes deployment manifests
          command: kubectl apply -f kubernetes-manifests/mygkeproject-deployment-gke-ingress-loadbalance.yaml
      - run:
          name: Load Kubernetes service manifests
          command: kubectl apply -f kubernetes-manifests/mygkeproject-service-gke-ingress-loadbalance.yaml
      - run:
          name: Load Kubernetes ingress manifests
          command: kubectl apply -f kubernetes-manifests/mygkeproject-ingressandcerts-gke-ingress-loadbalance.yaml

    description: Deploy application to Google Kubernetes Engine
    machine: true
      # Install `gcloud` and `kubectl` if not already installed.
      - gke/install
      # Initialize the `gcloud` CLI.
      - gke/init
      # Update a deployment Docker image.
      - gke/rollout-image:
          cluster: mygkeproject-gke-cluster # CHANGE 5/6 must upgrade to 0.2.0
          deployment: mygkeproject-deployment
          container: mygkeproject-container
          image: # change version when updating
      - build
# CHANGE 4/6: merge node build and image build/push
#      - Build-Push-Image-Docker:
#          requires:
#            - build
      - deploy:
            - build

A rather simple Dockerfile working with the above would be:

FROM  nginx:1.17
COPY ./build/ /usr/share/nginx/html

Hope this helps as the rather outdated documentation misled my efforts quite significantly.

1 Like

Thank you for posting your solution! I will pass your feedback on to the team to see what clarity we can add to the docs :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.