[root@k8s-master01 ~]# cat pod.yaml
1 apiVersion: v1 # 必选,API的版本号
2 kind: Pod # 必选,类型Pod
3 metadata: # 必选,元数据
4 name: nginx # 必选,符合RFC 1035规范的Pod名称
5 # namespace: default # 可选,Pod所在的命名空间,不指定默认为default,可以使用-n 指定namespace
6 labels: # 可选,标签选择器,一般用于过滤和区分Pod
7 app: nginx
8 role: frontend # 可以写多个
9 annotations: # 可选,注释列表,可以写多个
10 app: nginx
11 spec: # 必选,用于定义容器的详细信息
12 # initContainers: # 初始化容器,在容器启动之前执行的一些初始化操作
13 # - command:
14 # - sh
15 # - -c
16 # - echo "I am InitContainer for init some configuration"
17 # image: busybox
18 # imagePullPolicy: IfNotPresent
19 # name: init-container
20 containers: # 必选,容器列表
21 - name: nginx # 必选,符合RFC 1035规范的容器名称
22 image: nginx:1.15.2 # 必选,容器所用的镜像的地址
23 imagePullPolicy: IfNotPresent # 可选,镜像拉取策略, IfNotPresent: 如果宿主机有这个镜像,那就不需要拉取了. Always: 总是拉取, Never: 不管是否存储都不拉去
24 command: # 可选,容器启动执行的命令 ENTRYPOINT, arg --> cmd
25 - nginx
26 - -g
27 - "daemon off;"
28 workingDir: /usr/share/nginx/html # 可选,容器的工作目录
29 # volumeMounts: # 可选,存储卷配置,可以配置多个
30 # - name: webroot # 存储卷名称
31 # mountPath: /usr/share/nginx/html # 挂载目录
32 # readOnly: true # 只读
33 ports: # 可选,容器需要暴露的端口号列表
34 - name: http # 端口名称
35 containerPort: 80 # 端口号
36 protocol: TCP # 端口协议,默认TCP
37 env: # 可选,环境变量配置列表
38 - name: TZ # 变量名
39 value: Asia/Shanghai # 变量的值
40 - name: LANG
41 value: en_US.utf8
42 # resources: # 可选,资源限制和资源请求限制
43 # limits: # 最大限制设置
44 # cpu: 1000m
45 # memory: 1024Mi
46 # requests: # 启动所需的资源
47 # cpu: 100m
48 # memory: 512Mi
49 startupProbe: # 可选,检测容器内进程是否完成启动。注意三种检查方式同时只能使用一种。
50 # httpGet: # httpGet检测方式,生产环境建议使用httpGet实现接口级健康检查,健康检查由应用程序提供。
51 # path: /api/successStart # 检查路径
52 # port: 80
53 tcpSocket:
54 port: 80
55 # readinessProbe: # 可选,健康检查。注意三种检查方式同时只能使用一种。
56 # httpGet: # httpGet检测方式,生产环境建议使用httpGet实现接口级健康检查,健康检查由应用程序提供。
57 # path: / # 检查路径
58 # port: 80 # 监控端口
59 # livenessProbe: # 可选,健康检查
60 #exec: # 执行容器命令检测方式
61 #command:
62 #- cat
63 #- /health
64 #httpGet: # httpGet检测方式
65 # path: /_health # 检查路径
66 # port: 8080
67 # httpHeaders: # 检查的请求头
68 # - name: end-user
69 # value: Jason
70 # tcpSocket: # 端口检测方式
71 # port: 80
72 # initialDelaySeconds: 60 # 初始化时间
73 # timeoutSeconds: 2 # 超时时间
74 # periodSeconds: 5 # 检测间隔
75 # successThreshold: 1 # 检查成功为1次表示就绪
76 # failureThreshold: 2 # 检测失败2次表示未就绪
77 # lifecycle:
78 # postStart: # 容器创建完成后执行的指令, 可以是exec httpGet TCPSocket
79 # exec:
80 # command:
81 # - sh
82 # - -c
83 # - 'mkdir /data/ '
84 # preStop:
85 # httpGet:
86 # path: /
87 # port: 80
88 # exec:
89 # command:
90 # - sh
91 # - -c
92 # - sleep 9
93 restartPolicy: Always # 可选,默认为Always,容器故障或者没有启动成功,那就自动该容器,Onfailure: 容器以不为0的状态终止,自动重启该容器, Never:无论何种状态,都不会重启
94 #nodeSelector: # 可选,指定Node节点
95 # region: subnet7
96 # imagePullSecrets: # 可选,拉取镜像使用的secret,可以配置多个
97 # - name: default-dockercfg-86258
98 # hostNetwork: false # 可选,是否为主机模式,如是,会占用主机端口
99 # volumes: # 共享存储卷列表
100 # - name: webroot # 名称,与上述对应
101 # emptyDir: {} # 挂载目录
102 # #hostPath: # 挂载本机目录
103 # # path: /etc/hosts
104 #
105
[root@k8s-master01 ~]#
[root@k8s-master01 ~]# cat -n pod.yaml
1 apiVersion: v1 # 必选,API的版本号
2 kind: Pod # 必选,类型Pod
3 metadata: # 必选,元数据
4 name: nginx # 必选,符合RFC 1035规范的Pod名称
5 # namespace: default # 可选,Pod所在的命名空间,不指定默认为default,可以使用-n 指定namespace
6 labels: # 可选,标签选择器,一般用于过滤和区分Pod
7 app: nginx
8 role: frontend # 可以写多个
9 annotations: # 可选,注释列表,可以写多个
10 app: nginx
11 spec: # 必选,用于定义容器的详细信息
12 # initContainers: # 初始化容器,在容器启动之前执行的一些初始化操作
13 # - command:
14 # - sh
15 # - -c
16 # - echo "I am InitContainer for init some configuration"
17 # image: busybox
18 # imagePullPolicy: IfNotPresent
19 # name: init-container
20 containers: # 必选,容器列表
21 - name: nginx # 必选,符合RFC 1035规范的容器名称
22 image: nginx:1.15.2 # 必选,容器所用的镜像的地址
23 imagePullPolicy: IfNotPresent # 可选,镜像拉取策略, IfNotPresent: 如果宿主机有这个镜像,那就不需要拉取了. Always: 总是拉取, Never: 不管是否存储都不拉去
24 command: # 可选,容器启动执行的命令 ENTRYPOINT, arg --> cmd
25 - nginx
26 - -g
27 - "daemon off;"
28 workingDir: /usr/share/nginx/html # 可选,容器的工作目录
29 # volumeMounts: # 可选,存储卷配置,可以配置多个
30 # - name: webroot # 存储卷名称
31 # mountPath: /usr/share/nginx/html # 挂载目录
32 # readOnly: true # 只读
33 ports: # 可选,容器需要暴露的端口号列表
34 - name: http # 端口名称
35 containerPort: 80 # 端口号
36 protocol: TCP # 端口协议,默认TCP
37 env: # 可选,环境变量配置列表
38 - name: TZ # 变量名
39 value: Asia/Shanghai # 变量的值
40 - name: LANG
41 value: en_US.utf8
42 # resources: # 可选,资源限制和资源请求限制
43 # limits: # 最大限制设置
44 # cpu: 1000m
45 # memory: 1024Mi
46 # requests: # 启动所需的资源
47 # cpu: 100m
48 # memory: 512Mi
49 startupProbe: # 可选,检测容器内进程是否完成启动。注意三种检查方式同时只能使用一种。
50 # httpGet: # httpGet检测方式,生产环境建议使用httpGet实现接口级健康检查,健康检查由应用程序提供。
51 # path: /api/successStart # 检查路径
52 # port: 80
53 tcpSocket:
54 port: 80
55 # readinessProbe: # 可选,健康检查。注意三种检查方式同时只能使用一种。
56 # httpGet: # httpGet检测方式,生产环境建议使用httpGet实现接口级健康检查,健康检查由应用程序提供。
57 # path: / # 检查路径
58 # port: 80 # 监控端口
59 # livenessProbe: # 可选,健康检查
60 #exec: # 执行容器命令检测方式
61 #command:
62 #- cat
63 #- /health
64 #httpGet: # httpGet检测方式
65 # path: /_health # 检查路径
66 # port: 8080
67 # httpHeaders: # 检查的请求头
68 # - name: end-user
69 # value: Jason
70 # tcpSocket: # 端口检测方式
71 # port: 80
72 # initialDelaySeconds: 60 # 初始化时间
73 # timeoutSeconds: 2 # 超时时间
74 # periodSeconds: 5 # 检测间隔
75 # successThreshold: 1 # 检查成功为1次表示就绪
76 # failureThreshold: 2 # 检测失败2次表示未就绪
77 # lifecycle:
78 # postStart: # 容器创建完成后执行的指令, 可以是exec httpGet TCPSocket
79 # exec:
80 # command:
81 # - sh
82 # - -c
83 # - 'mkdir /data/ '
84 # preStop:
85 # httpGet:
86 # path: /
87 # port: 80
88 # exec:
89 # command:
90 # - sh
91 # - -c
92 # - sleep 9
93 restartPolicy: Always # 可选,默认为Always,容器故障或者没有启动成功,那就自动该容器,Onfailure: 容器以不为0的状态终止,自动重启该容器, Never:无论何种状态,都不会重启
94 #nodeSelector: # 可选,指定Node节点
95 # region: subnet7
96 # imagePullSecrets: # 可选,拉取镜像使用的secret,可以配置多个
97 # - name: default-dockercfg-86258
98 # hostNetwork: false # 可选,是否为主机模式,如是,会占用主机端口
99 # volumes: # 共享存储卷列表
100 # - name: webroot # 名称,与上述对应
101 # emptyDir: {} # 挂载目录
102 # #hostPath: # 挂载本机目录
103 # # path: /etc/hosts
104 #
105
[root@k8s-master01 ~]# kubectl create -f pod.yaml
pod/nginx created
[root@k8s-master01 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 0/1 Running 0 13s
[root@k8s-master01 ~]# kubectl describe po ## 看看报错没
[root@k8s-master01 ~]# kubectl get po -oyaml
apiVersion: v1
items:
- apiVersion: v1
kind: Pod
metadata:
annotations:
app: nginx
creationTimestamp: "2021-02-04T15:02:11Z"
labels:
app: nginx
role: frontend
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:app: {}
f:labels:
.: {}
f:app: {}
f:role: {}
f:spec:
f:containers:
k:{"name":"nginx"}:
.: {}
f:command: {}
f:env:
.: {}
k:{"name":"LANG"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"TZ"}:
.: {}
f:name: {}
f:value: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:ports:
.: {}
k:{"containerPort":80,"protocol":"TCP"}:
.: {}
f:containerPort: {}
f:name: {}
f:protocol: {}
f:resources: {}
f:startupProbe:
.: {}
f:failureThreshold: {}
f:periodSeconds: {}
f:successThreshold: {}
f:tcpSocket:
.: {}
f:port: {}
f:timeoutSeconds: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:workingDir: {}
f:dnsPolicy: {}
f:enableServiceLinks: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
manager: kubectl-create
operation: Update
time: "2021-02-04T15:02:11Z"
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:conditions:
k:{"type":"ContainersReady"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Initialized"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Ready"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
f:containerStatuses: {}
f:hostIP: {}
f:phase: {}
f:podIP: {}
f:podIPs:
.: {}
k:{"ip":"172.16.122.135"}:
.: {}
f:ip: {}
f:startTime: {}
manager: kubelet
operation: Update
time: "2021-02-04T15:03:31Z"
name: nginx
namespace: default
resourceVersion: "132890"
uid: dcdc7ae1-5525-4116-bde0-754823ce2c78
spec:
containers:
- command:
- nginx
- -g
- daemon off;
env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: en_US.utf8
image: nginx:1.15.2
imagePullPolicy: IfNotPresent
name: nginx
ports:
- containerPort: 80
name: http
protocol: TCP
resources: {}
startupProbe:
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 80
timeoutSeconds: 1
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-k2flf
readOnly: true
workingDir: /usr/share/nginx/html
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: k8s-master02
preemptionPolicy: PreemptLowerPriority
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-k2flf
secret:
defaultMode: 420
secretName: default-token-k2flf
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:02:11Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:03:31Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:03:31Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:02:11Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://255070fae5ee0207bb7df1583e4b71b97f06596b4c052aa4ec31b697b5bc59c7
image: nginx:1.15.2
imageID: docker-pullable://nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424
lastState: {}
name: nginx
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2021-02-04T15:02:12Z"
hostIP: 192.168.0.108
phase: Running
podIP: 172.16.122.135
podIPs:
- ip: 172.16.122.135
qosClass: BestEffort
startTime: "2021-02-04T15:02:11Z"
kind: List
metadata:
resourceVersion: ""
selfLink: ""
[root@k8s-master01 ~]#
[root@k8s-master01 ~]# kubectl get po -oyaml
apiVersion: v1
items:
- apiVersion: v1
kind: Pod
metadata:
annotations:
app: nginx
creationTimestamp: "2021-02-04T15:02:11Z"
labels:
app: nginx
role: frontend
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:app: {}
f:labels:
.: {}
f:app: {}
f:role: {}
f:spec:
f:containers:
k:{"name":"nginx"}:
.: {}
f:command: {}
f:env:
.: {}
k:{"name":"LANG"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"TZ"}:
.: {}
f:name: {}
f:value: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:ports:
.: {}
k:{"containerPort":80,"protocol":"TCP"}:
.: {}
f:containerPort: {}
f:name: {}
f:protocol: {}
f:resources: {}
f:startupProbe:
.: {}
f:failureThreshold: {}
f:periodSeconds: {}
f:successThreshold: {}
f:tcpSocket:
.: {}
f:port: {}
f:timeoutSeconds: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:workingDir: {}
f:dnsPolicy: {}
f:enableServiceLinks: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
manager: kubectl-create
operation: Update
time: "2021-02-04T15:02:11Z"
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:conditions:
k:{"type":"ContainersReady"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Initialized"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Ready"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
f:containerStatuses: {}
f:hostIP: {}
f:phase: {}
f:podIP: {}
f:podIPs:
.: {}
k:{"ip":"172.16.122.135"}:
.: {}
f:ip: {}
f:startTime: {}
manager: kubelet
operation: Update
time: "2021-02-04T15:03:31Z"
name: nginx
namespace: default
resourceVersion: "132890"
uid: dcdc7ae1-5525-4116-bde0-754823ce2c78
spec:
containers:
- command:
- nginx
- -g
- daemon off;
env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: en_US.utf8
image: nginx:1.15.2
imagePullPolicy: IfNotPresent
name: nginx
ports:
- containerPort: 80
name: http
protocol: TCP
resources: {}
startupProbe:
failureThreshold: 3
periodSeconds: 10
successThreshold: 1 # 新增
tcpSocket:
port: 80
timeoutSeconds: 1
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-k2flf
readOnly: true
workingDir: /usr/share/nginx/html
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: k8s-master02
preemptionPolicy: PreemptLowerPriority
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-k2flf
secret:
defaultMode: 420
secretName: default-token-k2flf
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:02:11Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:03:31Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:03:31Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2021-02-04T15:02:11Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://255070fae5ee0207bb7df1583e4b71b97f06596b4c052aa4ec31b697b5bc59c7
image: nginx:1.15.2
imageID: docker-pullable://nginx@sha256:d85914d547a6c92faa39ce7058bd7529baacab7e0cd4255442b04577c4d1f424
lastState: {}
name: nginx
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2021-02-04T15:02:12Z"
hostIP: 192.168.0.108
phase: Running
podIP: 172.16.122.135
podIPs:
- ip: 172.16.122.135
qosClass: BestEffort
startTime: "2021-02-04T15:02:11Z"
kind: List
metadata:
resourceVersion: ""
selfLink: ""
[root@k8s-master01 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 2m9s