Search code examples
jsonkuberneteshaproxy-ingress

kubernetes apply changes of existing service from json


I need help to understand how can I update my svc configuration using a json file : my svc is up and runing but it is not the type i want, it is a cluster ip and I'd like to change it to a ingress kind and type load balancer: curently here is the service :

kubectl -n nifitest get svc -o wide
simplenifi-all-node   ClusterIP      192.164.115.193   <none>          8080/TCP,6007/TCP,10000/TCP   44h   app=nifi,nifi_cr=simplenifi

now I want to deploy a service that point to the ingress

so is tere a kubectl command like apply to use a json file and will it update the svc using a json file ?

Thank you for your help


Solution

  • You need to create new service with loadbalancer type. You cannot update the previous one (from type: ClusterIP to type: LoadBalancer) cause it is immutable.

    By the way, I have given the format of loadbalancer service in both yaml and json as an example template, you can use them according to your need.

    In Json format:

    {
       "apiVersion": "v1",
       "kind": "Service",
       "metadata": {
          "name": "my-service"
       },
       "spec": {
          "selector": {
             "app": "MyApp"
          },
          "ports": [
             {
                "protocol": "TCP",
                "port": 80,
                "targetPort": 9376
             }
          ],
          "clusterIP": "192.164.115.193",
          "type": "LoadBalancer"
       },
       "status": {
          "loadBalancer": {
             "ingress": [
                {
                   "ip": "192.0.2.127"
                }
             ]
          }
       }
    }
    

    In Yaml format:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
    spec:
      selector:
        app: MyApp
      ports:
        - protocol: TCP
          port: 80
          targetPort: 9376
      clusterIP: 192.164.115.193
      type: LoadBalancer
    status:
      loadBalancer:
        ingress:
        - ip: 192.0.2.127