Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to specify a custom namespace to deploy with Cloud Deploy and Helm?

Maybe I missed something, but I didn't find an option to do that.

Target does not provide an option for namespace

apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
name: my-app
description: main application pipeline
serialPipeline:
stages:
- targetId: dev-1
profiles: [ ]
---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: dev-1
description: development cluster
gke:
cluster: projects/my-project/locations/europe-west1/clusters/gke1

 Providing a namespace in the skaffold.yaml didn't work 

apiVersion: skaffold/v2beta26
kind: Config
metadata:
name: my-app
build:
artifacts:
- image: eu.gcr.io/my-repo/my-app
ko:
dir: services/my-app
deploy:
helm:
releases:
- name: my-app
chartPath: helm/my-app
namespace: my-ns
artifactOverrides:
images.myApp: eu.gcr.io/my-repo/my-app

Any other options or suggestions?

0 6 1,816
6 REPLIES 6

glen_yu
Google Developer Expert
Google Developer Expert

Can you provide your full YAML (be sure to redact any credentials/private info).  It's hard to debug when you provide just a small piece of the puzzle.

Sure, it is "just" a basic helm deployment, which works with skaffold, but for some reason not with Cloud Deploy (it tries deploying to default namespace)

what's the error you get when it tries to deploy?

Well it deploys to default namespace

Actually it seems this might be a Cloud Deploy issue (or I am doing something wrong). Or did anyone use Helm with a namespace successfully? According to documentation "Then when you promote the release, Google Cloud Deploy uses skaffold apply to apply the manifests and deploy the images to your Google Kubernetes Engine cluster."

However, when looking up the documentation for skaffold apply 

Note: skaffold apply always uses kubectl to deploy resources to a target cluster, regardless of deployment configuration in the provided skaffold.yaml. Only a small subset of deploy configuration is honored when running skaffold apply: [...]

 

The helm namespace is not in this subset

Unfortunately this looks like it's a limitation of skaffold apply...

I have logged a bug on the skaffold GitHub page which I think relates to this and I encountered previously. skaffold deploy will pass the Skaffold --namespace flag to the chart but it appears Cloud Deploy (which uses skaffold render and then skaffold apply) will not.

You can work around this if you can modify the chart template; adding the following lines should ensure that the render and apply stage enforces the namespace directive (and defaults to default if not provided):

metadata:
  name: {{ include "demochart.fullname" . }}
  namespace: {{ .Release.namespace }}

Hope this helps,
 
David