1

I'm not sure which component in kubernetes do such job. Maybe kube-api-server or kube-controller-manager, since they both has a parameter named: "service-cluster-ip-range".

And I wonder to know if the assignment could be disable?

Thanks

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
vincent pli
  • 349
  • 1
  • 6
  • What is your objective for wanting to do this? – Daniel Mann Aug 31 '21 at 13:11
  • Actually, I'm in a multiple tenant scenario with solution of "controller-plane as service". So, in tenant cluster I do not want the SVC be assign a Cluster IP, the SVC should be sync to super cluster(not tenant cluster) and then assign IP and sync back to tenant cluster. – vincent pli Aug 31 '21 at 13:14

3 Answers3

0

Not sure what exactly you meant by disabling the assignment but you can also use spec.ClusterIP with the value of None to use the service in headless mode. This allows you to use other service discovery mechanisms, without being tied to Kubernetes' implementation by using pods addresses directly. Example:

apiVersion: v1
kind: Service
metadata:
  name: headless-svc
spec:
  clusterIP: None 
  selector:
    app: web
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
Qasim Sarfraz
  • 5,822
  • 2
  • 20
  • 26
  • Thanks Sarfraz, actually I want the kubernetes do not assign cluster ip to my service. no matter it's a headless or normal one. – vincent pli Aug 31 '21 at 13:25
0

At the beginning I will explain why ClusterIP is assigned at all:

A Kubernetes Service is an abstraction which defines a logical set of Pods running somewhere in your cluster, that all provide the same functionality. When created, each Service is assigned a unique IP address (also called clusterIP). This address is tied to the lifespan of the Service, and will not change while the Service is alive. Pods can be configured to talk to the Service, and know that communication to the Service will be automatically load-balanced out to some pod that is a member of the Service.

ClusterIP is created by-design in the moment of creating the Kubernetes Service. It is also not possible to change it while the Service is alive. It is not possible to simply turn off address assignment. The IP address is assigned from the --service-cluster-ip-range pool which is configured in api-server and kube-controller config.

The answer of the user Qasim Sarfraz is good. This is really the only option to do anything with ClusterIP:

You can use a headless Service to interface with other service discovery mechanisms, without being tied to Kubernetes' implementation.

See also:

Mikołaj Głodziak
  • 4,775
  • 7
  • 28
  • Thanks Mikotaj, very helpful. Do you know which component in kubernetes take charge of the job I mean assign the Cluster IP? – vincent pli Sep 02 '21 at 01:09
  • In the documentation, you'll find the general answer that `ClusterIP` assigns Kubernetes. As far as I know, one of the `kube-controller` processes makes this. – Mikołaj Głodziak Sep 02 '21 at 07:37
  • There is controller named `service` in the `kube-controller`, after I disable it, the assign is still happen, so I guess I need more research on it and expect people still could contribute to the issue, thanks – vincent pli Sep 14 '21 at 07:02
0

After some research, finally I found the cluster ip is assigned by kube-api-server: it assign the validate cluster ip before stored the object to etcd!

See the link: https://pkg.go.dev/k8s.io/kubernetes/pkg/registry/core/service@v1.22.1

and you also can found related code in the kubernetes repository on github.

So I guess it cannot be disabled : )

vincent pli
  • 349
  • 1
  • 6