0

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

Ait Zaid
  • 129
  • 12
  • do you strictly need JSON or YAML will also be ok? – Vasili Angapov Jan 29 '21 at 12:11
  • I don't know the think is that service is already running so i got it's configuration using this command : ```kubectl -n nifitest get service simplenifi-all-node -o jsonpath='{}{"\n"}' a``` and i got a json that i tried to modify but once that json is modified how to apply the changes to kubernetes ? thank you – Ait Zaid Jan 29 '21 at 13:01
  • 1
    Valid JSON should generally also be valid YAML; you should be able to `kubectl apply -f new-service.json` if you really want to write the Service description in JSON. – David Maze Jan 29 '21 at 16:36

1 Answers1

2

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
Sahadat Hossain
  • 3,583
  • 2
  • 12
  • 19
  • yhank you can you explain me what is the clusterIp refering to ? thank you – Ait Zaid Jan 29 '21 at 13:04
  • @AitZaid loadbalancer have `ClusterIP` for communication inside the cluster, and also a `ExternalIP` for communicating with the outside of the cluster. `externalIP`s are not managed by Kubernetes and are the responsibility of the cluster administrator. For more info you can read from official [docs](https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer) – Sahadat Hossain Jan 29 '21 at 13:07
  • 1
    you're right you need to redeploy it I thought you can reupdate it but – Ait Zaid Feb 01 '21 at 13:32