When you create any Kubernetes object, such as a Pod, Deployment, and Service, you can assign a name to it. The names in Kubernetes are spatially unique, which means you cannot assign the same name in the Pods.
Kubernetes allows us to assign a name with the following restrictions:
- Up to 253 characters
- Lowercase of alphabet and numeric characters
- May contain special characters in the middle, but only dashs (-) and dots (.)
For assigning a name to the Pod, follow the following steps:
- The following example is the Pod YAML configuration that assigns the Pod name as
my-pod
to the container name asmy-container
; you can successfully create it as follows:
# cat my-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
# kubectl create -f my-pod.yaml
pod "my-pod" created
# kubectl get pods
NAME READY STATUS RESTARTS AGE
my-pod 0/1 Running 0 4s
- You can use the...