'Update istio-ingressgateway with yaml instead of kubectl edit

I test tcp-based service from book...

To complete this task, I need to expose port 31400...

I found that I can do this using this command : KUBE_EDITOR="nano" kubectl edit svc istio-ingressgateway -n istio-system

and enter manually this :

  • name: tcp nodePort: 30851 port: 31400, protocol: TCP targetPort: 31400

I work as expected, but how do the same task using yaml and kubectl apply ?

Thanks for your help,

WCDR



Solution 1:[1]

1 - Get current configuration :

$ kubectl get -n istio-system service istio-ingressgateway -o yaml

Output look like :

apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {...,"kind":"Service",..."app":"istio-ingressgateway"...
  ...
  labels:
    app: istio-ingressgateway
    ...
    spec:
    ...
    ports:
     ...
     >>>> insert block here <<<<
    selector:
    ...
...

2 - Patch it with yq or manually...

https://github.com/mikefarah/yq

3 - Apply change :

 $ kubectl apply -n istio-system -f - <<EOF
    apiVersion: v1
    kind: Service
    ...
    EOF

Output must be :

service/istio-ingressgateway configured

Enjoy...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1