问题描述
我需要在Kubernetes复制控制器中设置一个静态主机名. Docker带有一些运行时标志来支持它,但是,Kubernetes复制控制器似乎不支持它.环境:OS-CentOS 6.6使用sysctl更改变量kernel.hostname的方法不适用于K8s复制控制器.主机名未更改.使用:sysctl kernel.hostname读取当前的主机名,以及sysctl kernel.hostname = NEW_HOSTNAME
I need to set a static hostname in a Kubernetes replication controller. Docker supports it with some runtime flags, however, Kubernetes replication controllers don't appear to support it.The environment: OS - CentOS 6.6Approach to use sysctl to change the variable kernel.hostname does not work for a K8s replication controller. The host name is not changed.Use:sysctl kernel.hostnameto read the current hostname, andsysctl kernel.hostname=NEW_HOSTNAME
是否可以在Kubernetes复制控制器中设置主机名?
Is it possible to set a hostname in a Kubernetes replication controller?
推荐答案
在1.7中,您可以直接在部署"规范中设置主机名
In 1.7 you can set the hostname directly in the Deployment spec
spec:
replicas: 1
template:
spec:
hostname: myhostname
containers:
...
旧答案
现在1.2已着陆,您可以使用pod.beta.kubernetes.io/hostname
批注在Replication Controller或Deployment spec
中设置静态主机名.
Now that 1.2 has landed, you can set a static hostname in a Replication Controller or Deployment spec
using the pod.beta.kubernetes.io/hostname
annotation.
spec:
replicas: 1
template:
metadata:
annotations:
pod.beta.kubernetes.io/hostname: myhostname
labels:
...
这篇关于是否可以在Kubernetes复制控制器中设置主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!