Change default container names which have been created via a pod configuration file in kubernetes

7/24/2018

I have a pod configuration file with which I am able to create a pod that runs some containers with specific names.

apiVersion: v1
kind: Pod
metadata:
  name: hazelcast
spec:
  restartPolicy: Never
  containers:
- name: bkregasp01
  image: hazelcast/hazelcast
  ports:
    - containerPort: 5701
  env:
    - name: JAVA_OPTS
      value: -Dhazelcast.rest.enabled=true
- name: bkregasp05
  image: hazelcast/hazelcast
  ports:
    - containerPort: 5701
  env:
    - name: JAVA_OPTS
      value: -Dhazelcast.rest.enabled=true

Once I create this pod I can check the containers created via the command

docker ps -a 

And I can see that the names have been changed:

NAMES
k8s_bkregasp01_hazelcast_default_acf5ebb0-8f2b-11e8-b2f0-0800275a6976_0
k8s_bkregasp05_hazelcast_default_acf5ebb0-8f2b-11e8-b2f0-0800275a6976_0

How can I avoid this so that the containers keep their original names specified in the configuration file?

-- Omair
cloud
docker
kubernetes
namespaces
virtual-machine

1 Answer

7/24/2018

How can I avoid this so that the containers keep their original names specified in the configuration file?

This is something you can not avoid since k8s depends on such naming convention to locate containers.

So far, the convention including a k8s as prefix plus pod name (e.g., hazelcast), namespace (default). see technical design details from https://github.com/kubernetes/kubernetes/issues/199

-- shawmzhu
Source: StackOverflow