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?
Each Pod in a StatefulSet derives its hostname from the name of the StatefulSet and the ordinal of the Pod. The pattern for the constructed hostname is $(statefulset name)-$(ordinal) . Save this answer.
The letter – J, K or L donates the pod of the mother's family, and the calf (male or female) will stay with her family for life. The number is the next available for that pod. For example, the last calf born to J pod in 2020 was named J58, the next calf born to a J pod mother will be J59.
You can do a DNS query from any pod and you would get the FQDN. cluster-domain. example is just a example in the documentation. cluster.
if you use deployment then the naming convention as follows:
|--- Deployment: < name >
│-----
└─ Replica Set: < name >-< rs >
│--------
└─ Pod: < name >-< rs>-< RandomString >
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With