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
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
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
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:
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 : )