Kustomize: Overlay can't override port in Service or Deployment

Created on 16 Jul 2018  路  7Comments  路  Source: kubernetes-sigs/kustomize

# base/frontend.yaml
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  ports:
  - name: http 
    port: 80
  selector:
    app: frontend
  type: NodePort

I want to change the port in an overlay.

# overlay/port.yaml
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  ports:
  - name: http 
    port: 90

Building the overlay results in the following yaml (note that http port is declared twice with two values):

apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  ports:
  - name: http
    port: 90
  - name: http
    port: 80
  selector:
    app: frontend
  type: NodePort

Same thing happens with Deployments.

Most helpful comment

I also came here for this reason. I didn't find deletion mentioned in your docs. In fact, I found deletion mentioned in "eschewed features" stating you wouldn't be supporting it. I spent at least an hour reading your docs and examples.

Perhaps $patch should be mentioned in the README or something?

All 7 comments

Similar to #143, you need to delete the port 80.

apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  ports:
  - port: 80
    $patch: delete
  - name: http
    port: 90

I also came here for this reason. I didn't find deletion mentioned in your docs. In fact, I found deletion mentioned in "eschewed features" stating you wouldn't be supporting it. I spent at least an hour reading your docs and examples.

Perhaps $patch should be mentioned in the README or something?

I agree with @jazoom , and frankly this type of syntax was one of the things that turned me away from starting to use Kustomize. I don鈥檛 find this intuitive even if it is documented.

True. Even with the example provided here and in the other issue it still took me about 5 tries of trial and error to get it right. Apparently port is the only field that works on, and you must not include any other fields from the item you want to delete. And in containers, apparently containerPort is the one that works.

The default behaviour of adding to rather than overwriting the array was quite unexpected.

And to make matters even more confusing, I just discovered that it works totally differently for volumes. The following will actually overwrite the hostPath called datadir from base with the new path. No $patch required. This is the intuitive behaviour, but it should at least be consistent from one array to the next.

    spec:
      volumes:
      - name: datadir
        hostPath:
          path: /C/something/something
          type: DirectoryOrCreate

Other than this issue, I've found Kustomize to be a pleasure to use. Thank you for building and open-sourcing it.

@nicksnyder @jazoom thanks for the excellent feedback. Filed #306

@monopole no probs

This is terrible 馃槥

If we change port number - new one is being added, and if we change port name - it's being replaced.

Was this page helpful?
0 / 5 - 0 ratings