我知道如果我们定义 LoadBalancer 可以将 Public-IP 设置为静态 IP,但是我们可以为服务设置一个静态 Cluster IP 吗?
例子:
**NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE**
service/my-application-service ClusterIP 10.111.67.245 <none> 80/TCP 11d
最佳答案
看起来您可以在 ClusterIP 类服务的 spec 下指定 clusterIP 字段。
例子:
apiVersion: v1
kind: Service
metadata:
name: myawesomeservice
namespace: myawesomenamespace
spec:
clusterIP: 10.43.11.51
...
文档中最相关的片段
“如果地址是手动指定的,在范围内(根据系统配置)且未被使用,它将被分配给服务;否则服务创建将失败”- https://kubernetes.io/docs/reference/kubernetes-api/services-resources/service-v1/
这是完整的段落。
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
来源:https://kubernetes.io/docs/reference/kubernetes-api/services-resources/service-v1/
关于kubernetes - 如何在 Kubernetes 中定义静态 ClusterIP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62262656/