<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>You can't.</p>
<p>It is the property of the pods of a <code>Deployment</code> that they do not have an identity associated with them.</p>
<p>You could have a look at <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer"><code>Statefulset</code></a> instead of a Deployment if you want the pods to have a state.</p>
<p>From the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>So, if you have a <code>Statefulset</code> object named <code>myapp</code> with two replicas, the pods will be named as <code>myapp-0</code> and <code>myapp-1</code>.</p>
