[root@k8s-master ~]# kubectl explain pods KIND: Pod VERSION: v1
DESCRIPTION: Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.
FIELDS: apiVersion <string> APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
kind <string> Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
metadata <Object> Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata spec <Object> Specification of the desired behavior of the pod. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status status <Object> Most recently observed status of the pod. This data may not be up to date. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
root@k8s-master mainfests]$ kubectl get pods --show-labels #查看pod标签 NAME READY STATUS RESTARTS AGE LABELS pod-demo 2/2 Running 0 25s app=myapp,tier=frontend
[root@k8s-master mainfests]$ kubectl get pods -l app #过滤包含app的标签 NAME READY STATUS RESTARTS AGE pod-demo 2/2 Running 0 1m [root@k8s-master mainfests]$ kubectl get pods -L app NAME READY STATUS RESTARTS AGE APP pod-demo 2/2 Running 0 1m myapp
[root@k8s-master mainfests]$ kubectl label pods pod-demo release=canary #给pod-demo打上标签 pod/pod-demo labeled [root@k8s-master mainfests]$ kubectl get pods -l app --show-labels NAME READY STATUS RESTARTS AGE LABELS pod-demo 2/2 Running 0 1m app=myapp,release=canary,tier=frontend
[root@k8s-master mainfests]$ kubectl label pods pod-demo release=stable --overwrite #修改标签 pod/pod-demo labeled [root@k8s-master mainfests]$ kubectl get pods -l release NAME READY STATUS RESTARTS AGE pod-demo 2/2 Running 0 2m [root@k8s-master mainfests]$ kubectl get pods -l release,app NAME READY STATUS RESTARTS AGE pod-demo 2/2 Running 0 2m
②标签选择器
等值关系标签选择器:=, == , != (kubectl get pods -l app=test,app=dev)
集合关系标签选择器: KEY in (v1,v2,v3), KEY notin (v1,v2,v3) !KEY (kubectl get pods -l “app in (test,dev)”)
操作符: in notin:Values字段的值必须是非空列表 Exists NotExists: Values字段的值必须是空列表
③节点标签选择器
1 2 3 4 5 6 7 8 9 10 11
[root@k8s-master mainfests]$ kubectl explain pod.spec nodeName <string> NodeName is a request to schedule this pod onto a specific node. If it is non-empty, the scheduler simply schedules this pod onto that node, assuming that it fits resource requirements.
nodeSelector <map[string]string> NodeSelector is a selector which must be truefor the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
#(3)重新创建pod-demo,可以看到固定调度在k8s-node01节点上 [root@k8s-master mainfests]# kubectl delete -f pod-demo.yaml pod "pod-demo" deleted
[root@k8s-master mainfests]# kubectl create -f pod-demo.yaml pod/pod-demo created [root@k8s-master mainfests]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE pod-demo 2/2 Running 0 20s 10.244.1.13 k8s-node01 [root@k8s-master mainfests]# kubectl describe pod pod-demo ...... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 42s default-scheduler Successfully assigned default/pod-demo to k8s-node01