I'm wondering if there is a proper naming convention for generated pod names in Kubernetes. By generated pod names I mean the name displayed in both kubectl get pods
or, for instance, by querying the heapster api:
$ curl -s http://192.168.99.100:32416/api/v1/model/namespaces/kube-system/pods
[
"kube-addon-manager-minikube",
"kube-dns-v20-8gsbl",
"kubernetes-dashboard-tp9kc",
"heapster-kj8hh",
"influxdb-grafana-stg3s"
]
$ curl -s http://192.168.99.100:32416/api/v1/model/namespaces/default/pods
[
"my-nginx-2723453542-065rx"
]
If there is no convention (as it looks like) are there any scenario(s) in which the common format: pod name
+ 5 alpha-numeric chars
is true?
When you create a Deployment, it creates a replicaset named as:
replica-set-name
= <deployment-name>-<random-string>
The replicaset, in turn, creates the pods adding another random string* to them:
<replica-set-name>-<random-string>
$ kubectl create deploy nginx --image=nginx
deployment.apps/nginx created
$ kubectl scale --replicas=3 deploy/nginx
deployment.extensions/nginx scaled
$ kubectl get replicaset
NAME DESIRED CURRENT READY AGE
nginx-554b9c67f9 3 3 3 96s
$ kubectl get po
NAME READY STATUS RESTARTS AGE
nginx-554b9c67f9-c5cv4 1/1 Running 0 74s
nginx-554b9c67f9-hjkjq 1/1 Running 0 74s
nginx-554b9c67f9-wbwdm 1/1 Running 0 2m7s
In fact, the "random strings" aren’t completely random at all.
To prevent “bad words”, vowels and the numbers 0, 1 and 3 were removed from the rand.String
function (PRs for reference: #37225 and #50070).
So, the <random-string>
will be composed by a combination of the following alphanumeric characters: bcdfghjklmnpqrstvwxz2456789
.
if you use deployment then the naming convention as follows:
|--- Deployment: < name >
│-----
└─ Replica Set: < name >-< rs >
│--------
└─ Pod: < name >-< rs>-< RandomString >
if you use deployments, for sake of human operators you'll find your pods names as <replicaset>-<[0-9a-z]{5}>
where replicaset is <deployment>-<id>
. For kubernetes it self, naming of pods is irrelevant.