<pre><code>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
</code></pre>
<p>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?</p>

<p>It's better if you use, <code>statefulset</code> instead of <code>deployment</code>. Statefulset's pod name will be like <code>&lt;statefulsetName-0&gt;</code>,<code>&lt;statefulsetName-1&gt;</code>... And you will need a <code>clusterIP</code> service. with which you can bound your pods. see the doc for more details. <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/" rel="nofollow noreferrer">Ref</a></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: test-svc
  labels:
    app: test
spec:
  ports:
  - port: 8080
    name: web
  clusterIP: None
  selector:
    app: test
</code></pre>
<pre><code>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
</code></pre>
<p>Here, The pod name will be like this <code>test-StatefulSet-0</code>.</p>
