kubernetes – Is there a way to add a suffix to a pod’s name when using the kubectl scale command

I’m running a command like this:

# add an executor pod
kubectl scale deployments executor --replicas 1

# show new pod
kubectl get pods
# NAME                              READY   STATUS    RESTARTS   AGE
# executor-8cb7dc8689-w58ls           1/1     Running   0        11m

This is typically done to to run some command via kubectl exec.

We have multiple people on the team occasionally doing this and sometimes forgetting to scale back down, leaving these resources up.

Is there a way I can dynamically add a suffix just to the new pod’s name when scaling so I can have some indication of ownership? For example, something like this:

echo $USER
# myusername
kubectl scale deployments executor --replicas 1 --name-suffix $USER

kubectl get pods
# NAME                                         READY   STATUS    RESTARTS   AGE
# executor-8cb7dc8689-w58ls-myusername           1/1     Running   0        11m

Read more here: Source link