POD
定义
Pod 是可以在 Kubernetes 中创建和管理的、最小的可部署的计算单元,每个Pod包含了一个pause容器,pause容器时Pod的父容器,负责僵尸进程的回收管理,通过pause容器可以支持同一个Pod里面的多个容器共享存储、网络、ipc等。
说明:Pod一般不直接操作,通过 Deployment、StatefulSet、DaemonSet控制。
[root@master01 ~]# kubectl get pod -n kube-system -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-5f6d4b864b-k45q5 1/1 Running 4 4d9h 192.168.44.13 node01 <none> <none>
calico-node-58hbg 1/1 Running 4 4d9h 192.168.44.12 master03 <none> <none>
calico-node-dlj65 1/1 Running 3 4d9h 192.168.44.11 master02 <none> <none>
calico-node-jqb6h 1/1 Running 4 4d9h 192.168.44.14 node02 <none> <none>
calico-node-r8fl5 1/1 Running 5 4d9h 192.168.44.10 master01 <none> <none>
calico-node-wv4vx 1/1 Running 4 4d9h 192.168.44.13 node01 <none> <none>
coredns-867d46bfc6-ljdjr 1/1 Running 4 4d9h 172.29.55.5 node01 <none> <none>
metrics-server-595f65d8d5-6k4wq 1/1 Running 6 4d9h 172.21.231.133 node02 <none> <none>
[root@master01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b6b4384467b1 d45bf977dfbf "start_runit" 2 hours ago Up 2 hours k8s_calico-node_calico-node-r8fl5_kube-system_e06be2e7-75dc-4029-b468-f3b7f253ab44_5
683c51344750 registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2 "/pause" 2 hours ago Up 2 hours k8s_POD_calico-node-r8fl5_kube-system_e06be2e7-75dc-4029-b468-f3b7f253ab44_5
使用Pod
创建一个pod
vim pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
role: frontend
annotations:
app: nginx
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
command:
- nginx
- -g
- "daemon off;"
workingDir: /usr/share/nginx/html
ports:
- name: http
containerPort: 80
protocol: TCP
env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: en_US.utf8
restartPolicy: Always
[root@master01 pod_demo]# kubectl create -f pod.yaml
pod/nginx created
[root@master01 pod_demo]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 0/1 ContainerCreating 0 13s
[root@master01 pod_demo]# kubectl get po --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx 0/1 ContainerCreating 0 30s app=nginx,role=frontend
[root@master01 pod_demo]# kubectl create -f pod.yaml -n kube-public
pod/nginx created
[root@master01 pod_demo]# kubectl get po -n kube-public
NAME READY STATUS RESTARTS AGE
nginx 0/1 ContainerCreating 0 12s
#如果pod在命名空间下已存在 再次创建回报错
[root@master01 pod_demo]# kubectl create -f pod.yaml -n kube-public
Error from server (AlreadyExists): error when creating "pod.yaml": pods "nginx" already exists
# 修改配置使用apply命令
[root@master01 pod_demo]# vim pod.yaml
[root@master01 pod_demo]# kubectl apply -f pod.yaml -n kube-public
pod/nginx configured
标签:Kubernetes,master01,calico,nginx,Pod,root,pod
From: https://www.cnblogs.com/arvinhuang/p/16839060.html