标签:space 虚拟化 default rto 存在 应用 检查 https try
#containers
[root@master ~]# kubectl explain pods.spec.containers.
name <string> -required- #容器名,必选字段
image <string> #镜像,默认是dockerhub仓库,可以客户自己定义仓库
imagePullPolicy <string> #镜像获取策略,Always(总是下载),IfNotPresent(如果本地不存在就下载),Never(从不下载,使用本地镜像),默认IfNotPresent,如果镜像标签是latest,默认是Always
ports <[]Object> # 对象列表,可以暴漏多个端口,也可以对每个端口的属性进行单独定义,此处暴漏端口只是提供额外信息,不能限制系统是否真的暴漏
- containerPort <integer>#容器端口
hostIP <string> #主机IP(一般不需要)
hostPort <integer> #节点端口
name <string> #名称
protocol <string> #使用协议,默认是TCP
args <[]string> #为command传递参数,相当于docker的CMD
command <[]string> #运行的命令 相当于docker中的ENTRYPOINT
Description | docker field name | kubernetes field name |
---|---|---|
the command run by container | entrypoint | command |
the arguments passed to the command | Cmd | args |
说明:
1、如果pod不提供command和args则默认使用docker镜像中的entrypoint和Cmd;
2、如果pod只提供command但是不提供args,则只使用command,docker镜像中的entrypoint和cmd都会被忽略;
3、如果pod不提供command但是只提供args,则使用docker镜像中默认的entrypoint,并且把pod中定义的args当作参数传给entrypoint,docker镜像中的cmd被忽略;
4、如果pod既提供command又提供args,那么就直接运行command和args,docker镜像中的entrypoint和cmd都被忽略。
显示所有pod的所有标签
[root@master ~]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
client-f5cdb799f-pklmc 1/1 Running 0 19h pod-template-hash=f5cdb799f,run=client
myapp-9b4987d5-47sjj 1/1 Running 0 19h pod-template-hash=9b4987d5,run=myapp
myapp-9b4987d5-684q9 1/1 Running 0 19h pod-template-hash=9b4987d5,run=myapp
myapp-9b4987d5-djdr9 1/1 Running 0 19h pod-template-hash=9b4987d5,run=myapp
nginx-deploy-84cbfc56b6-tcssz 1/1 Running 0 23h pod-template-hash=84cbfc56b6,run=nginx-deploy
pod-demo 2/2 Running 1 16h app=myapp,tier=frontend
筛选包含app标签的pod
[root@master ~]# kubectl get pods -l app
NAME READY STATUS RESTARTS AGE
pod-demo 2/2 Running 2 17h
显示所有pod标签为app的值,没有则显示为空
[root@master ~]# kubectl get pods -L app
NAME READY STATUS RESTARTS AGE APP
client-f5cdb799f-pklmc 1/1 Running 0 20h
myapp-9b4987d5-47sjj 1/1 Running 0 20h
myapp-9b4987d5-684q9 1/1 Running 0 20h
myapp-9b4987d5-djdr9 1/1 Running 0 20h
nginx-deploy-84cbfc56b6-tcssz 1/1 Running 0 24h
pod-demo 2/2 Running 2 17h myapp
使用kubectl label给资源打标签
#语法
kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N
[--resource-version=version] [options]
[root@master manifests]# kubectl label pod pod-demo release=canary
pod/pod-demo labeled
[root@master manifests]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
client-f5cdb799f-pklmc 1/1 Running 0 20h pod-template-hash=f5cdb799f,run=client
myapp-9b4987d5-47sjj 1/1 Running 0 20h pod-template-hash=9b4987d5,run=myapp
myapp-9b4987d5-684q9 1/1 Running 0 20h pod-template-hash=9b4987d5,run=myapp
myapp-9b4987d5-djdr9 1/1 Running 0 20h pod-template-hash=9b4987d5,run=myapp
nginx-deploy-84cbfc56b6-tcssz 1/1 Running 0 24h pod-template-hash=84cbfc56b6,run=nginx-deploy
pod-demo 2/2 Running 2 17h app=myapp,release=canary,tier=frontends
筛选同时包含多个标签的pod
[root@master manifests]# kubectl get pods -l release,app
NAME READY STATUS RESTARTS AGE
pod-demo 2/2 Running 2 17h
许多资源支持内嵌字段定义其使用的标签选择器:
annotations:与label不同的地方:它不能用于挑选资源对象,仅用于为对象提供"元数据",没有键值长度限制。
[root@master ~]# kubectl explain pods.spec.
nodeName <string> #指定node名称
nodeSelector <map[string]string> #使用标签选择器
给node01打标签disktype=ssd,然后运行pod-demo使用节点标签选择器,使之运行在node01上
#给node01打标签
[root@master manifests]# kubectl label node node01 disktype=ssd
node/node01 labeled
[root@master manifests]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master Ready master 43h v1.13.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master,node-role.kubernetes.io/master=
node01 Ready <none> 42h v1.13.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/hostname=node01
node02 Ready <none> 42h v1.13.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node02
#编辑pod-demo.yaml
[root@master manifests]# vim pod-demo_1.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
#labels: {"app": "myapp","tier": "frontend"} 和下面效果一样,建议使用下面格式
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
- name: busybox
image: busybox
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
nodeSelector:
disktype: ssd
#重新部署pod-demo,需提前删除原pod-demo
[root@master manifests]# kubectl delete -f pod-demo.yaml
pod "pod-demo" deleted
[root@master manifests]# kubectl apply -f pod-demo_1.yaml
pod/pod-demo created
#验证结果
[root@master manifests]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
client-f5cdb799f-pklmc 1/1 Running 0 20h 10.244.2.7 node02 <none> <none>
myapp-9b4987d5-47sjj 1/1 Running 0 20h 10.244.1.13 node01 <none> <none>
myapp-9b4987d5-684q9 1/1 Running 0 20h 10.244.1.12 node01 <none> <none>
myapp-9b4987d5-djdr9 1/1 Running 0 20h 10.244.2.13 node02 <none> <none>
nginx-deploy-84cbfc56b6-tcssz 1/1 Running 0 24h 10.244.2.4 node02 <none> <none>
pod-demo 2/2 Running 0 10s 10.244.1.14 node01 <none> <none>
增加annotations注解,使用kubectl describe查看
[root@master manifests]# cat pod-demo_1.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
tier: frontend
annotations:
white.io/created-by: "cluster white"
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
- name: busybox
image: busybox
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
nodeSelector:
disktype: ssd
#需要使用kubectl describe pods pod-demo来查看才看的到
[root@master manifests]# kubectl describe pods pod-demo
Name: pod-demo
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: node01/10.0.0.11
Start Time: Fri, 29 Mar 2019 11:30:51 +0800
Labels: app=myapp
tier=frontend
Annotations: white.io/created-by: cluster white
Status: Running
IP: 10.244.1.15
... ...
https://www.cnblogs.com/linuxk
马永亮. Kubernetes进阶实战 (云计算与虚拟化技术丛书)
Kubernetes-handbook-jimmysong-20181218
标签:space 虚拟化 default rto 存在 应用 检查 https try
原文地址:https://www.cnblogs.com/wlbl/p/10652884.html