(cd overlays/production/ && kustomize edit set image my-app=*:0.0.1 && kustomize build)
Output:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: my-app-production
spec:
replicas: 4
selector:
matchLabels:
app: my-app
template:
spec:
containers:
- image: gcr.io/my-platform/my-app:0.0.1
name: my-app
(cd overlays/staging && kustomize edit set image my-app=*:0.0.1 && kustomize build)
Output:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: my-app-staging
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
spec:
containers:
- image: gcr.io/my-platform/my-app:0.0.1
name: my-app
Note: above 2 commands modifies the production kustomization.yaml and staging/kustomization.yaml so before running the below command
to create deployment for production & staging, remove newTag
from these files
i.e.
images:
- name: my-app
newName: gcr.io/my-platform/my-app
newTag: 0.0.1
(cd overlays/ && kustomize edit set image my-app=*:0.0.1 && kustomize build)
Output:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: my-app-production
spec:
replicas: 4
selector:
matchLabels:
app: my-app
template:
spec:
containers:
- image: gcr.io/my-platform/my-app
name: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: my-app-staging
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
spec:
containers:
- image: gcr.io/my-platform/my-app
name: my-app
As you can see the image tag is not present in the output
The reason why kustomize edit set image
doesn't work is because it only updates the tag in current directory.
After running above command if you check the overlays/kustomization.yaml, you'll see the image newTag
was added.
-
cd into each deployment and the run
kustomize edit set image
andpopd
to run the multibase kustomization. But it might be too much if there are many deployments of a same app with different names. -
Use image label and replace it using
sed
command, it will sovle the issue but that's not the kustomize way