GitHub 操作工作流中的 Kustomization 未部署到 GKE

时间:2021-05-27 10:44:30

标签: github kubernetes cloud google-kubernetes-engine github-actions

我有一个关于 Github 操作的工作流,用于构建、测试容器并将其推送到 GKE。 我遵循了 https://docs.github.com/en/actions/guides/deploying-to-google-kubernetes-engine 中概述的步骤,但我的构建一直失败。 失败来自构建过程的 Kustomization 阶段。

这是错误的样子:

Run ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
  ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
  ./kustomize build . | kubectl apply -f -
  kubectl rollout status deployment/$DEPLOYMENT_NAME
  kubectl get services -o wide
  shell: /usr/bin/bash -e ***0***
  env:
    PROJECT_ID: ***
    GKE_CLUSTER: codematictest
    GKE_ZONE: us-east1-b
    DEPLOYMENT_NAME: codematictest
    IMAGE: codematictest
    CLOUDSDK_METRICS_ENVIRONMENT: github-actions-setup-gcloud
    KUBECONFIG: /home/runner/work/codematic-test/codematic-test/fb7d2ebb-4c82-4d43-af10-5b0b62bab1fd
Error: Missing kustomization file 'kustomization.yaml'.

Usage:
  kustomize edit set image [flags]

Examples:

The command
  set image postgres=eu.gcr.io/my-project/postgres:latest my-app=my-registry/my-app@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
will add

images:
- name: postgres
  newName: eu.gcr.io/my-project/postgres
  newTag: latest
- digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
  name: my-app
  newName: my-registry/my-app

to the kustomization file if it doesn't exist,
and overwrite the previous ones if the image name exists.

The command
  set image node:8.15.0 mysql=mariadb alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
will add

images:
- name: node
  newTag: 8.15.0
- name: mysql
  newName: mariadb
- digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
  name: alpine

to the kustomization file if it doesn't exist,
and overwrite the previous ones if the image name exists.


Flags:
  -h, --help   help for image

Error: Process completed with exit code 1.

我的 GitHub 工作流文件如下所示:

name: gke

on: push

env:
  PROJECT_ID: ${{ secrets.GKE_PROJECT }}
  GKE_CLUSTER: codematictest
  GKE_ZONE: us-east1-b
  DEPLOYMENT_NAME: codematictest
  IMAGE: codematictest

jobs:
  setup-build-publish-deploy:
    name: Setup, Build, Publish, and Deploy
    defaults:
      run:
        working-directory: api
    runs-on: ubuntu-latest
    environment: production

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    # Setup gcloud CLI
    - uses: google-github-actions/setup-gcloud@v0.2.0
      with:
        service_account_key: ${{ secrets.GKE_SA_KEY }}
        project_id: ${{ secrets.GKE_PROJECT }}

    # Configure Docker to use the gcloud command-line tool as a credential
    # helper for authentication
    - run: |-
        gcloud --quiet auth configure-docker

    # Get the GKE credentials so we can deploy to the cluster
    - uses: google-github-actions/get-gke-credentials@v0.2.1
      with:
        cluster_name: ${{ env.GKE_CLUSTER }}
        location: ${{ env.GKE_ZONE }}
        credentials: ${{ secrets.GKE_SA_KEY }}

    # Build the Docker image
    - name: Build
      run: |-
        docker build \
          --tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
          --build-arg GITHUB_SHA="$GITHUB_SHA" \
          --build-arg GITHUB_REF="$GITHUB_REF" \
          .

    # Push the Docker image to Google Container Registry
    - name: Publish
      run: |-
        docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"

    # Set up kustomize
    - name: Set up Kustomize
      run: |-
        curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
        chmod u+x ./kustomize

    # Deploy the Docker image to the GKE cluster
    - name: Deploy
      run: |-
        ./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
        ./kustomize build . | kubectl apply -f -
        kubectl rollout status deployment/$DEPLOYMENT_NAME
        kubectl get services -o wide

1 个答案:

答案 0 :(得分:1)

kustomization 文件(如 repository 中所述)应位于下一个文件结构中:

~/someApp
├── deployment.yaml
├── kustomization.yaml
└── service.yaml