I started with the Github Action template from Google for Deployment to GKE. Everything worked as it should and now i want to extend the functionality for different environments (i.e. a push on the master branch goes to prod and one on dev should deploy to stage).
In the template this should be in the very last section of the job:
# 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
I changed the kustomize build
line to:
kubectl kustomize kubernetes/overlays/stage | kubectl apply -f -
This because my folder structure for the kustomize files looks like this:
+---kubernetes
| +---base
| | deployment.yml
| | kustomization.yml
| | service.yml
| |
| \---overlays
| +---prod
| | deployment.yml
| | kustomization.yml
| | service.yml
| |
| \---stage
| deployment.yml
| kustomization.yml
| service.yml
And for the start all the deplyoment.yml
and service.yml
are still the same as before I added the environment structure, only the kustomization.yml in the overlays changed to:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ../../base
patchesStrategicMerge:
- deployment.yml
- service.yml
When I now run the Github Action workflow the deployment failes with the error:
Error: Missing kustomization file 'kustomization.yaml'.
When using local kubectl command it produces the consolidated output of the wanted environment:
kubectl kustomize kubernetes/overlays/stage