Makiki
Makiki

Reputation: 81

How to define a static ClusterIP in Kubernetes?

I know we can set Public-IP as a static if we define LoadBalancer but can we set a static Cluster IP for service?

Example:

**NAME                           TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE**
service/my-application-service   ClusterIP  10.111.67.245   <none>        80/TCP     11d

Upvotes: 8

Views: 9726

Answers (1)

Brandon
Brandon

Reputation: 361

It looks like you can specify the clusterIP field under spec on a ClusterIP kind service.

Example:

apiVersion: v1
kind: Service
metadata:
  name: myawesomeservice
  namespace: myawesomenamespace
spec:
  clusterIP: 10.43.11.51
  ...

Most relevant snippet from docs

"If an address is specified manually, is in-range (as per system configuration), and is not in use, it will be allocated to the service; otherwise creation of the service will fail" - https://kubernetes.io/docs/reference/kubernetes-api/services-resources/service-v1/

And here is the full paragraph.

spec

clusterIP (string)

clusterIP is the IP address of the service and is usually assigned randomly. If an address is specified manually, is in-range (as per system configuration), and is not in use, it will be allocated to the service; otherwise creation of the service will fail. This field may not be changed through updates unless the type field is also being changed to ExternalName (which requires this field to be blank) or the type field is being changed from ExternalName (in which case this field may optionally be specified, as describe above). Valid values are "None", empty string (""), or a valid IP address. Setting this to "None" makes a "headless service" (no virtual IP), which is useful when direct endpoint connections are preferred and proxying is not required. Only applies to types ClusterIP, NodePort, and LoadBalancer. If this field is specified when creating a Service of type ExternalName, creation will fail. This field will be wiped when updating a Service to type ExternalName. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies

src: https://kubernetes.io/docs/reference/kubernetes-api/services-resources/service-v1/

Upvotes: 16

Related Questions