<p>We are using kustomize for our kubernetes deployments in this way:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:${IMAGE_VERSION}
        ports:
        - containerPort: 80
</code></pre>

<p>and deploy this yaml substituting the variable IMAGE_VERSION with 1.7.9</p>

<pre><code>kustomize build ./nginx/overlays/dev/ | sed -e 's|${IMAGE_VERSION}'"|1.7.9|g" | kubectl apply -f -
</code></pre>

<p>Since kubectl 1.14 supports kustomize.</p>

<p>now we can do something very nice like this</p>

<pre><code>kubectl apply -k ./
</code></pre>

<p>but how to substitute the IMAGE_VERSION variable with this new command?</p>

KiteUp
<p>You have to create a <code>kustomization.yaml</code> file containing the customizations.</p>

<p>i.e:</p>

<pre><code># kustomization.yaml
bases:
- ../base
images:
  - name: nginx-pod
    newTag: 1.15
    newName: nginx-pod-2
</code></pre>

<p>And for the templates, you create a base folder containing the kustomization.yaml with reference to the deployment and dependencies, i.e:</p>

<pre><code># ../base/kustomization.yaml
resources:
- deployment.yaml
</code></pre>

<p>and</p>

<pre><code># ../base/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx-pod
</code></pre>

<p>Run the command:</p>

<p><code>kubectl apply -k</code></p>

<p>The above command will compile the customization and generate the following yaml to be applied to the cluster:</p>

<pre><code># Modified Base Resource
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      # The image image tag has been changed for the container
      - name: nginx
        image: nginx-pod-2:1.15
</code></pre>
