创建pod时不指定标签,则为空。所以运行 kubectl get pods -L app
将会输出以下内容(其中标签列为空)
删除该pod时,依然会重新建立
建议您显式地定义一个有意义的标签以确保更好的控制 Kubernetes 部署。此外,在创建 Service 时,还需要使用该标签作为 selector,以确保 Service 能够正确地连接到与 Deployment 关联的 Pod。
其实k8s内部已经创建了labels:
kind: Deployment
apiVersion: apps/v1
metadata:
name: msapp
namespace: sgai-test
selfLink: /apis/apps/v1/namespaces/sgai-test/deployments/msapp
uid: 8890efe0-3d6b-4432-8772-b6cf92fa7a2c
resourceVersion: '3061013'
generation: 1
creationTimestamp: '2023-05-18T05:24:53Z'
labels:
run: msapp
annotations:
deployment.kubernetes.io/revision: '1'
spec:
replicas: 1
selector:
matchLabels:
run: msapp
template:
metadata:
creationTimestamp: null
labels:
run: msapp
spec:
containers:
- name: msapp
image: 'master01:5000/sgai-ms-run-app:2.0'
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
status:
observedGeneration: 1
replicas: 1
updatedReplicas: 1
readyReplicas: 1
availableReplicas: 1
conditions:
- type: Available
status: 'True'
lastUpdateTime: '2023-05-18T05:24:57Z'
lastTransitionTime: '2023-05-18T05:24:57Z'
reason: MinimumReplicasAvailable
message: Deployment has minimum availability.
- type: Progressing
status: 'True'
lastUpdateTime: '2023-05-18T05:24:57Z'
lastTransitionTime: '2023-05-18T05:24:53Z'
reason: NewReplicaSetAvailable
message: ReplicaSet "msapp-69bc4c6846" has successfully progressed.