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

标签 kubernetes

我知道如果我们定义 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/

相关文章:

kubernetes - 未知标志 : --export while copying secret from one namespace to another kubectl

kubernetes - 在针对KubernetesPodOperator的DAG设置中我在做什么错

kubernetes - core_dns 卡在 ContainerCreating 状态

kubernetes - Kubernetes版本已升级,但kubectl显示不同版本

kubernetes - Kubernetes-HPA不会自动缩放Pod

apache-spark - spark-submit:403错误,客户端系统:匿名错误

kubernetes - Quarkus Kubernetes 运算符 : how to set environment variables in application container (not operator container)?

Azure 容器/Kubernetes 服务 - 网络接口(interface)和 IP 未删除

kubernetes - 预安装 Hook Helm - 用户友好的错误消息

kubernetes - 代理可能不可用错误 Kafka 架构注册表