Google Cloud Deploy not activating correct Skaffold profile

230 Views Asked by At

I am using Google Cloud Build & Google Cloud Deploy with Skaffold profiles to manage spec of pods between Staging and Production environments, but the rendered manifests do not have the spec according to the profiles and the manifest in the default section is picked up by Cloud Deploy. What am I doing wrong?

(Attaching my Cloud Build, Cloud Deploy & Skaffold config files)

skaffold.yaml

apiVersion: skaffold/v4beta1
kind: Config

build:
  artifacts:
    - image: ***

deploy:
  kubectl: {}

manifests:
  rawYaml:
    - k8s-deployment.yaml

profiles:
  - name: stage
    activation:
      - kubeContext: <STAGE_KUBE_CONTEXT>
      - command: stage
    build:
      artifacts:
        - image: ***

  - name: prod
    activation:
      - kubeContext: <PROD_KUBE_CONTEXT>
      - command: prod
    build:
      artifacts:
        - image: ***

    deploy:
      kubectl: {}

cloudbuild.yaml

steps:
  - name: "asia.gcr.io/YOUR_PROJECT_ID/sonar-scanner:latest"
    args:
      [
        "-Dsonar.projectKey=***",
        "-Dsonar.organization=***",
        "-Dsonar.sources=.",
        "-Dsonar.host.url=https://sonarcloud.io",
        "-Dsonar.login=${_SONAR_TOKEN}",
      ]
  - name: "gcr.io/cloud-builders/docker"
    args:
      [
        "build",
        "-t",
        "asia.gcr.io/YOUR_PROJECT_ID/***/***:$SHORT_SHA",
        ".",
      ]
  - name: "gcr.io/cloud-builders/docker"
    args:
      ["push", "asia.gcr.io/YOUR_PROJECT_ID/***/***:$SHORT_SHA"]

  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
    entrypoint: "bash"
    args:
      - "-c"
      - >
        gcloud deploy releases create stage-release-$SHORT_SHA
        --project=YOUR_PROJECT_ID
        --region=asia-east2
        --delivery-pipeline=***
        --source=./
        --images=***=asia.gcr.io/YOUR_PROJECT_ID/***/***:$SHORT_SHA

substitutions:
  _SONAR_TOKEN: "YOUR_SONAR_TOKEN"

clouddeploy.yaml

apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
  name: ***
description: gke deployment pipeline
serialPipeline:
  stages:
    - targetId: staging
      profiles:
        - stage
    - targetId: production
      profiles:
        - prod

---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
  name: staging
description: staging cluster
gke:
  cluster: ***

---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
  name: production
description: production cluster
gke:
  cluster: ***
#

The generated manifest if from the default skaffold build & deploy part (outside the profile section)

2

There are 2 best solutions below

0
On

If you have different configurations between the prod and staging environments, Kubernetes manifests should be defined separately and specify them in the corresponding profiles.Here are documentations for Scaffold and Cloud Deploy that are good references. [1][2]

[1] https://skaffold.dev/docs/environment/profiles/

[2] https://cloud.google.com/deploy/docs/overview#about_skaffold_and

0
On

Your Skaffold deploy stanza should be located beneath each profile. In your example, the deploy stanza is common to both profiles. This is why the same manifest is being applied to both profiles.

See example, here:

https://cloud.google.com/deploy/docs/using-skaffold/managing-manifests#profiles_with_raw_manifests

I hope this helps.