Warm tip: This article is reproduced from stackoverflow.com, please click
bazel google-cloud-build google-kubernetes-engine kubectl kubernetes

How to Apply Output of Previous Step to Kubernetes Cluster

发布于 2020-04-11 22:46:50

I have a simple cloudbuild.yaml file which runs a Bazel command. This command returns a Kubernetes configuration in form as a log output.

My goal is to take the output of the first step and apply it to my Kubernetes cluster.

steps:
  - name: gcr.io/cloud-builders/bazel
    args: ["run", "//:kubernetes"]

  - name: "gcr.io/cloud-builders/kubectl"
    args: ["apply", "<log output of previous step>"]
    env:
      - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
      - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"

Update

I've tried the following:

- name: gcr.io/cloud-builders/bazel
  entrypoint: /bin/bash
  args:
    [
      "bazel",
      "run",
      "//:kubernetes",
      " > kubernetes.yaml",
    ]

- name: "gcr.io/cloud-builders/kubectl"
  args: ["apply", "-f", "kubernetes.yaml"]
  env:
    - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
    - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"

But then I get this error:

Running: kubectl apply -f kubernetes.yaml
error: the path "kubernetes.yaml" does not exist
Questioner
Florian Ludewig
Viewed
78
Emil Gi 2020-02-04 21:24

As everyone already suggested here use volumes.

Tweak your cloudbuild.yaml file like this:

- name: gcr.io/cloud-builders/bazel
  entrypoint: /bin/bash
  args:
    [
      "bazel",
      "run",
      "//:kubernetes",
      " > /workspace/kubernetes.yaml",
    ]

- name: "gcr.io/cloud-builders/kubectl"
  args: ["apply", "-f", "/workspace/kubernetes.yaml"]
  env:
    - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
    - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"