Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
kubernetes Deployment PodName setting
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      name: test
      labels:
        app: test
    spec:
      containers:
        - name: server
          image: test_ml_server:2.3
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: hostpath-vol-testserver
              mountPath: /app/test/api
#          env:
#            - name: POD_NAME
#              valueFrom:
#                fieldRef:
#                  fieldPath: template.metadata.name
        - name: testdb
          image: test_db:1.4
          ports:
            - name: testdb
              containerPort: 1433
          volumeMounts:
            - name: hostpath-vol-testdb
              mountPath: /var/opt/mssql/data
#          env:
#            - name: POD_NAME
#              valueFrom:
#                fieldRef:
#                  fieldPath: template.metadata.name
      volumes:
        - name: hostpath-vol-testserver
          hostPath:
            path: /usr/testhostpath/testserver
        - name: hostpath-vol-testdb
          hostPath:
            path: /usr/testhostpath/testdb

I want to set the name of the pod Because it communicates internally based on the name of the pod but when a pod is created, it cannot be used because the variable name is appended to the end. How can I set the pod name?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

It's better if you use, statefulset instead of deployment. Statefulset's pod name will be like <statefulsetName-0>,<statefulsetName-1>... And you will need a clusterIP service. with which you can bound your pods. see the doc for more details. Ref

apiVersion: v1
kind: Service
metadata:
  name: test-svc
  labels:
    app: test
spec:
  ports:
  - port: 8080
    name: web
  clusterIP: None
  selector:
    app: test
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: test-StatefulSet
  labels:
    app: test
spec:
  replicas: 1
  serviceName: test-svc
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      name: test
      labels:
        app: test
    spec:
      containers:
        - name: server
          image: test_ml_server:2.3
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: hostpath-vol-testserver
              mountPath: /app/test/api
        - name: testdb
          image: test_db:1.4
          ports:
            - name: testdb
              containerPort: 1433
          volumeMounts:
            - name: hostpath-vol-testdb
              mountPath: /var/opt/mssql/data
      volumes:
        - name: hostpath-vol-testserver
          hostPath:
            path: /usr/testhostpath/testserver
        - name: hostpath-vol-testdb
          hostPath:
            path: /usr/testhostpath/testdb

Here, The pod name will be like this test-StatefulSet-0.

over 4 years ago · Santiago Trujillo Report

0

if you are using the kind: Deployment it won't be possible ideally in this scenario you can use kind: Statefulset.

Instead of POD to POD communication, you can use the Kubernetes service for communication.

Still, statefulset manage the pod name in the sequence

statefulsetname - 0
statefulsetname - 1
statefulsetname - 2
over 4 years ago · Santiago Trujillo Report

0

You can't.

It is the property of the pods of a Deployment that they do not have an identity associated with them.

You could have a look at Statefulset instead of a Deployment if you want the pods to have a state.

From the docs:

Like a Deployment, a StatefulSet manages Pods that are based on an identical container spec. Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.

So, if you have a Statefulset object named myapp with two replicas, the pods will be named as myapp-0 and myapp-1.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!