gpt4 book ai didi

kubernetes - 如何在 Kubernetes 中定义静态 ClusterIP?

转载 作者:行者123 更新时间:2023-12-05 01:36:13 26 4
gpt4 key购买 nike

我知道如果我们定义 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 assignedrandomly. If an address is specified manually, is in-range (as persystem configuration), and is not in use, it will be allocated to theservice; otherwise creation of the service will fail. This field maynot be changed through updates unless the type field is also beingchanged to ExternalName (which requires this field to be blank) or thetype field is being changed from ExternalName (in which case thisfield may optionally be specified, as describe above). Valid valuesare "None", empty string (""), or a valid IP address. Setting this to"None" makes a "headless service" (no virtual IP), which is usefulwhen direct endpoint connections are preferred and proxying is notrequired. Only applies to types ClusterIP, NodePort, and LoadBalancer.If this field is specified when creating a Service of typeExternalName, creation will fail. This field will be wiped whenupdating 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com