Kubernetes pod naming convention

Naming Convention:

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>


Example:

$ 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

* Not random at all:

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.


If you use StatefulSets then the naming convention is:

|--- StatefulSets: < name >
│----------└─ Pod: < name >-< ordinal index >

e.g. postgresql-0