Meilan
Meilan

Reputation: 474

How to change a pod name

I'm very new to k8s and the related stuff, so this may be a stupid question: How to change the pod name?

I am aware the pod name seems set in the helm file, in my values.yaml, I have this:

...
hosts:
    - host: staging.application.com
      paths:
        ...
        - fullName: application
          svcPort: 80
          path: /*
...

Since the application is running in the prod and staging environment, and the pod name is just something like application-695496ec7d-94ct9, I can't tell which pod is for prod or staging and can't tell if a request if come from the prod or not. So I changed it to:

hosts:
    - host: staging.application.com
      paths:
        ...
        - fullName: application-staging
          svcPort: 80
          path: /*

I deployed it to staging, pod updated/recreated automatically but the pod name still remains the same. I was confused about that, and I don't know what is missing. I'm not sure if it is related to the fullnameOverride, but it's empty so it should be fine.

Upvotes: 1

Views: 2654

Answers (1)

gohm'c
gohm'c

Reputation: 15490

...the pod name still remains the same

The code snippet in your question likely the helm values for Ingress. In this case not related to Deployment of Pod.

Look into your helm template that define the Deployment spec for the pod, search for the name and see which helm value was assigned to it:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox  # <-- change & you will see the pod name change along. the helm syntax surrounding this field will tell you how the name is construct/assign
  labels:
    app: busybox
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
      - name: busybox
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["ash","-c","sleep 3600"]

Save the spec and apply, check with kubectl get pods --selector app=busybox. You should see 1 pod with name busybox prefix. Now if you open the file and change the name to custom and re-apply and get again, you will see 2 pods with different name prefix. Clean up with kubectl delete deployment busybox custom.

This example shows how the name of the Deployment is used for pod(s) underneath. You can paste your helm template surrounding the name field to your question for further examination if you like.

Upvotes: 2

Related Questions