2

I have a Kustomize like below:

├── base
│   ├── kustomization.yaml
|   ├── deployment.yaml
│   └── service.yaml
└── overlays
    └── development
        ├── kustomization.yaml
        └── service.yaml

I want to define my-service as NodePort, and use different nodePort value for each environment.

My base/service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app/name: my-service
  ports:
  - name: http
    protocol: TCP
    port: 9000
    targetPort: 80
  - name: https
    protocol: TCP
    port: 9001
    targetPort: 443
  type: NodePort

overlays/development/kustomization.yaml:

resources:
- ../../base
patchesStrategicMerge:
- service.yaml

And overlays/development/service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
  - name: http
    nodePort: 30000
  - name: https
    nodePort: 31000

But with above configurations, kustomize cannot make proper ports.

$ kubectl kustomize overlays/development
...
---
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports: []
  selector:
    app/name: my-service
  type: NodePort
---
...

What is wrong with my configurations?

Ellisein
  • 878
  • 6
  • 17

1 Answers1

0

to patch port, you have to specify port and protocol (I think those are the primary key attributes of the port)

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
  - port: 9000
    protocol: TCP
    nodePort: 30000
  - port: 9001
    protocol: TCP
    nodePort: 31000