apiVersion: group/version //指明api资源属于哪个群组和版本,同一个组
可以有多个版本
kubectl api-versions //查询命令
• kind: //标记创建的资源类型,k8s主要支持以下资源类别 Pod,ReplicaSet,Deployment,StatefulSet,DaemonSet,Job,Cronjob
• metadata: //元数据 name: //对像名称
namespace: //对象属于哪个命名空间 labels: //指定资源标签,标签是一种键值数据
• spec: //定义目标资源的期望状态
#kubectl explain pod //查询帮助文档
$ vim demo.yaml
apiVersion: v1
kind: Pod
metadata:
name: demo
labels:
app: demo
spec:
containers:
- name: ubuntu
image: ubuntu
command: ["/bin/sh", "-c", "sleep 3600"]
- name: nginx
image: nginx
创建自主式pod
kubectl create -f demo.yaml
删除自主式pod
kubectl deleate -f demo.yaml
$ kubectl get pod --show-labels //查看标签
NAME READY STATUS RESTARTS AGE LABELS
demo 2/2 Running 0 8s app=demo
• $ kubectl get pod -l app
NAME READY STATUS RESTARTS AGE demo 2/2 Running 0 34s
//过滤包含app的标签 NAME READY STATUS RESTARTS AGE APP
• $ kubectl get pod -L app
demo 2/2 Running 0 39s demo
$ kubectl label pod demo version=v1 //打标签
pod/demo labeled
• $ kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS demo 2/2 Running 0 4m1s app=demo,version=v1
• $ kubectl label pod demo app=nginx --overwrite //更改标签
pod/demo labeled
• $ kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS demo 2/2 Running 0 5m40s app=nginx,version=v1
$ kubectl label nodes server2 disktype=ssd
node/server2 labeled
$ kubectl get nodes -l disktype
NAME STATUS ROLES AGE VERSION
server2 Ready 6d v1.17.2
$ kubectl delete -f demo.yml
pod "demo" deleted
$ kubectl create -f demo.yaml
pod/demo created
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
demo 2/2 Running 0 2m16s 10.244.1.44 server2