Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set a hostname in a Kubernetes replication controller?

Tags:

kubernetes

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.6 Approach 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.hostname to read the current hostname, and sysctl kernel.hostname=NEW_HOSTNAME

Is it possible to set a hostname in a Kubernetes replication controller?

like image 515
Sergey Smola Avatar asked Jan 05 '16 10:01

Sergey Smola


People also ask

What is the difference between a replica set and a replication controller?

The replica set and the replication controller's key difference is that the replication controller only supports equality-based selectors whereas the replica set supports set-based selectors.

What is hostname in Kubernetes?

The hostname of a Container is the name of the Pod in which the Container is running. It is available through the hostname command or the gethostname function call in libc. The Pod name and namespace are available as environment variables through the downward API.

What is true about replication controller in Kubernetes?

A ReplicationController manages all the pods with labels that match the selector. It does not distinguish between pods that it created or deleted and pods that another person or process created or deleted. This allows the ReplicationController to be replaced without affecting the running pods. If specified, the .


1 Answers

In 1.7 you can set the hostname directly in the Deployment spec

spec:
  replicas: 1
  template:
    spec:
      hostname: myhostname
      containers:
        ...

Old Answer

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:
        ...
like image 148
morloch Avatar answered Oct 28 '22 15:10

morloch