参考资料
- https://kubernetes.io/zh/docs/reference/kubectl/overview/
- https://kubernetes.io/zh-cn/docs/reference/kubectl/generated/
kubectl 命令帮助
# kubectl --help
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner):
create Create a resource from a file or from stdin.
expose 使用 replication controller, service, deployment 或者 pod 并暴露它作为一个新的Kubernetes Service
run 在集群中运行一个指定的镜像
set 为 objects 设置一个指定的特征
Basic Commands (Intermediate):
explain 查看资源的文档
get 显示一个或更多 resources
edit 在服务器上编辑一个资源
delete Delete resources by filenames, stdin, resources and names, or by resources and label selector
Deploy Commands:
rollout Manage the rollout of a resource
scale 为 Deployment, ReplicaSet, Replication Controller 或者 Job 设置一个新的副本数量
autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量
Cluster Management Commands:
certificate 修改 certificate 资源.
cluster-info 显示集群信息
top Display Resource (CPU/Memory/Storage) usage.
cordon 标记 node 为 unschedulable
uncordon 标记 node 为 schedulable
drain Drain node in preparation for maintenance
taint 更新一个或者多个 node 上的 taints
Troubleshooting and Debugging Commands:
describe 显示一个指定 resource 或者 group 的 resources 详情
logs 输出容器在 pod 中的日志
attach Attach 到一个运行中的 container
exec 在一个 container 中执行一个命令
port-forward Forward one or more local ports to a pod
proxy 运行一个 proxy 到 Kubernetes API server
cp 复制 files 和 directories 到 containers 和从容器中复制 files 和 directories.
auth Inspect authorization
Advanced Commands:
diff Diff live version against would-be applied version
apply 通过文件名或标准输入流(stdin)对资源进行配置
patch 使用 strategic merge patch 更新一个资源的 field(s)
replace 通过 filename 或者 stdin替换一个资源
wait Experimental: Wait for a specific condition on one or many resources.
convert 在不同的 API versions 转换配置文件
Settings Commands:
label 更新在这个资源上的 labels
annotate 更新一个资源的注解
completion Output shell completion code for the specified shell (bash or zsh)
Other Commands:
alpha Commands for features in alpha
api-resources Print the supported API resources on the server
api-versions Print the supported API versions on the server, in the form of "group/version"
config 修改 kubeconfig 文件
plugin Provides utilities for interacting with plugins.
version 输出 client 和 server 的版本信息
Usage:
kubectl [flags] [options]
Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
命令详解
- kubectl annotate - 更新资源所关联的注解
- kubectl api-resources - 打印服务器上所支持的 API 资源
- kubectl api-versions - 以“组/版本”的格式输出服务端所支持的 API 版本
- kubectl apply - 基于文件名或标准输入,将新的配置应用到资源上
- kubectl attach - 连接到一个正在运行的容器
- kubectl auth - 检查授权信息
- kubectl autoscale - 对一个资源对象(Deployment、ReplicaSet 或 - ReplicationController )进行扩缩
- kubectl certificate - 修改证书资源
- kubectl cluster-info - 显示集群信息
- kubectl completion - 根据已经给出的 Shell(bash 或 zsh),输出 Shell 补全后的代码
- kubectl config - 修改 kubeconfig 配置文件
- kubectl convert - 在不同的 API 版本之间转换配置文件
- kubectl cordon - 标记节点为不可调度的
- kubectl cp - 将文件和目录拷入/拷出容器
- kubectl create - 通过文件或标准输入来创建资源
- kubectl debug - 创建用于排查工作负载和节点故障的调试会话
- kubectl delete - 通过文件名、标准输入、资源和名字删除资源,或者通过资源和标签选择器来删除资源
- kubectl describe - 显示某个资源或某组资源的详细信息
- kubectl diff - 显示目前版本与将要应用的版本之间的差异
- kubectl drain - 腾空节点,准备维护
- kubectl edit - 修改服务器上的某资源
- kubectl exec - 在容器中执行相关命令
- kubectl explain - 显示资源文档说明
- kubectl expose - 给定副本控制器、服务、Deployment 或 Pod,将其暴露为新的 kubernetes Service
- kubectl get - 显示一个或者多个资源信息
- kubectl kustomize - 从目录或远程 URL 中构建 kustomization
- kubectl label - 更新资源的标签
- kubectl logs - 输出 pod 中某容器的日志
- kubectl options - 打印所有命令都支持的共有参数列表
- kubectl patch - 基于策略性合并修补(Stategic Merge Patch)规则更新某资源中的字段
- kubectl plugin - 运行命令行插件
- kubectl port-forward - 将一个或者多个本地端口转发到 pod
- kubectl proxy - 运行一个 kubernetes API 服务器代理
- kubectl replace - 基于文件名或标准输入替换资源
- kubectl rollout - 管理资源的上线
- kubectl run - 在集群中使用指定镜像启动容器
- kubectl scale - 为一个 Deployment、ReplicaSet 或 - - - - ReplicationController 设置一个新的规模尺寸值
- kubectl set - 为对象设置功能特性
- kubectl taint - 在一个或者多个节点上更新污点配置
- kubectl top - 显示资源(CPU /内存/存储)使用率
- kubectl uncordon - 标记节点为可调度的
- kubectl version - 打印客户端和服务器的版本信息
- kubectl wait - 实验性:等待一个或多个资源达到某种状态
kubectl命令中的简写
kubectl命令中可以使用的缩写,具体如下:
- certificatesigningrequests (缩写 csr)
- componentstatuses (缩写 cs)
- configmaps (缩写 cm)
- customresourcedefinition (缩写 crd)
- daemonsets (缩写 ds)
- deployments (缩写 deploy)
- endpoints (缩写 ep)
- events (缩写 ev)
- horizontalpodautoscalers (缩写 hpa)
- ingresses (缩写 ing)
- limitranges (缩写 limits)
- namespaces (缩写 ns)
- networkpolicies (缩写 netpol)
- nodes (缩写 no)
- persistentvolumeclaims (缩写 pvc)
- persistentvolumes (缩写 pv)
- poddisruptionbudgets (缩写 pdb)
- pods (缩写 po)
- podsecuritypolicies (缩写 psp)
- replicasets (缩写 rs)
- replicationcontrollers (缩写 rc)
- resourcequotas (缩写 quota)
- serviceaccounts (缩写 sa)
- services (缩写 svc)
- statefulsets (缩写 sts)
- storageclasses (缩写 sc)
实例
kubect create
创建一个资源从一个文件或标准输入,与apply 区别是如果容器已经存在会报错
kubectl create deployment nginx --image=nginx:1.14
kubectl create -f my-nginx.yaml
kubect apply
kubectl apply (-f FILENAME | -k DIRECTORY)
#将传入标准输入的 JSON 应用到 pod
cat pod.json | kubectl apply -f -
# 应用 manifest.yaml 中匹配标签 app=nginx 的配置,并删除所有其他不在文件中并匹配标签 app=nginx 的资源
#注意: --prune 仍处于 Alpha
kubectl apply --prune -f manifest.yaml -l app=nginx
#应用 manifest.yaml 中的配置并删除文件中没有的所有其他配置映射
kubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap
kubectl run
在集群中运行一个指定的镜像
kubectl run nginx --image=nginx:1.16 --port=80 --replicas=1
kubectl expose
创建Service对象以将应用程序"暴露"于网络中
kubectl expose deployment/nginx --type="NodePort" --port=80 --name=nginx
kubect exec
kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] – COMMAND [args…]
# 进入Pod 容器
kubectl exec -it <pod-name> -n <namespace> -c <container-name> -- /bin/sh
# 在 Pod 中执行命令获取输出,默认在第一个容器中执行
kubectl exec pod/<pod_name> -- date
kubectl exec pod/<pod_name> -- curl -s http://172.10.1.111
# 在 Pod mypod 的 ruby-container 容器中执行 'date' 命令并获取输出
kubectl exec mypod -c ruby-container -- date
# 切换到原始终端模式;从 Pod mypod 将 stdin 发送到 ruby-container 中的 'bash',
# 并将 stdout/stderr 从 'bash' 发送回客户端
kubectl exec mypod -c ruby-container -i -t -- bash -il
# 在 Pod mypod 的第一个容器中列出 /usr 的内容,并按修改时间排序
# 如果你要在 Pod 中执行的命令具有任何与 kubectl 本身重叠的标志(例如 -i),
# 则必须使用两个破折号(--)来分隔命令的标志/参数
# 另请注意,不要用引号括住你的命令及其标志/参数,
# 除非这是你正常执行它的方式(即执行 ls -t /usr,而不是 "ls -t /usr")
kubectl exec mypod -i -t -- ls -t /usr
# 在 Deployment mydeployment 中的第一个 Pod 运行 'date' 命令并获取输出,默认使用 Pod 的第一个容器
kubectl exec deploy/mydeployment -- date
# 在 Service myservice 的第一个 Pod 运行 'date' 命令并获取输出,默认使用 Pod 的第一个容器
kubectl exec svc/myservice -- date
kubectl get
显示一个或更多resources资源
kubectl get cs # 查看集群状态
kubectl get nodes # 查看集群节点信息
kubectl get ns # ns:namespace,查看集群命名空间
kubectl get svc -n kube-system # svc:service,查看指定命名空间的服务
kubectl get pod <pod-name> -o wide # 查看Pod详细信息
kubectl get pod <pod-name> -o yaml # 以yaml格式查看Pod详细信息
kubectl get pods # 查看资源对象,查看所有Pod列表
kubectl get pods -n kube-system -o wide # 查看指定命名空间的pod详细信息
kubectl get pods -n kube-system --watch # 持续查看指定命名空间的pod状态变化
kubectl get ingress -o wide # 查看ingress详细信息
kubectl get rc,service # 查看资源对象,查看rc和service列表
kubectl get pod,svc,ep --show-labels # 查看pod,svc,ep能及标签信息
kubectl get all --all-namespaces # 查看所有的命名空间
kubectl get events # 获得当前命名空间下所有Events 事件的列表
kubectl clster-info
显示集群信息
kubectl cluster-info # 查看集群状态信息
kubectl describe
描述资源对象
kubectl describe nodes <node-name> # 显示Node的详细信息
kubectl describe pods/<pod-name> # 显示Pod的详细信息
kubectl top
显示资源(CPU/内存)使用情况。
- top 命令允许你查看节点或 Pod 的资源消耗情况。
- 此命令要求 Metrics Server 在服务器上被正确配置且正常运行。
# 查看节点资源使用情况(按内存排序)
kubectl top nodes --sort-by=memory
# 输出示例:
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
worker-node-1 5800m 72% 6143Mi 98%
worker-node-2 4200m 52% 5892Mi 95%
worker-node-3 3800m 47% 4321Mi 70%
# 按内存使用量排序所有Pod
kubectl top pods -A --sort-by=memory --use-protocol-buffers
# 输出示例:
NAMESPACE NAME CPU(cores) MEMORY(bytes)
bigdata seatunnel-2 71m 2704Mi
bigdata seatunnel-0 41m 2511Mi
kubectl scale
pod扩容与缩容
kubectl scale deployment nginx --replicas 5 # 扩容
kubectl scale deployment nginx --replicas 3 # 缩容
kubectl patch
如果一个容器已经在运行,这时需要对一些容器属性进行修改,又不想删除容器,或不方便通过replace的方式进行更新。kubernetes还提供了一种在容器运行时,直接对容器进行修改的方式,就是patch命令。
1)使用patch更新Node节点
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
2)使用patch更新由“node.json”文件中指定的类型和名称标识的节点
kubectl patch -f node.json -p '{"spec":{"unschedulable":true}}'
3)更新容器的镜像
kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
或
kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'
4)设置服务对外的IP
kubectl patch svc <svc-name> -n <namespace> -p '{"spec": {"type": "LoadBalancer", "externalIPs":["192.168.31.241"]}}'
kubectl api-resources
查看服务器上支持的API资源
# kubectl api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
endpoints ep true Endpoints
events ev true Event
limitranges limits true LimitRange
namespaces ns false Namespace
nodes no false Node
persistentvolumeclaims pvc true PersistentVolumeClaim
persistentvolumes pv false PersistentVolume
pods po true Pod
podtemplates true PodTemplate
replicationcontrollers rc true ReplicationController
resourcequotas quota true ResourceQuota
secrets true Secret
serviceaccounts sa true ServiceAccount
services svc true Service
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinition
apiservices apiregistration.k8s.io false APIService
controllerrevisions apps true ControllerRevision
daemonsets ds apps true DaemonSet
deployments deploy apps true Deployment
replicasets rs apps true ReplicaSet
statefulsets sts apps true StatefulSet
tokenreviews authentication.k8s.io false TokenReview
localsubjectaccessreviews authorization.k8s.io true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscaler
cronjobs cj batch true CronJob
jobs batch true Job
certificatesigningrequests csr certificates.k8s.io false CertificateSigningRequest
leases coordination.k8s.io true Lease
events ev events.k8s.io true Event
daemonsets ds extensions true DaemonSet
deployments deploy extensions true Deployment
ingresses ing extensions true Ingress
networkpolicies netpol extensions true NetworkPolicy
podsecuritypolicies psp extensions false PodSecurityPolicy
replicasets rs extensions true ReplicaSet
ingresses ing networking.k8s.io true Ingress
networkpolicies netpol networking.k8s.io true NetworkPolicy
runtimeclasses node.k8s.io false RuntimeClass
poddisruptionbudgets pdb policy true PodDisruptionBudget
podsecuritypolicies psp policy false PodSecurityPolicy
clusterrolebindings rbac.authorization.k8s.io false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io false ClusterRole
rolebindings rbac.authorization.k8s.io true RoleBinding
roles rbac.authorization.k8s.io true Role
priorityclasses pc scheduling.k8s.io false PriorityClass
csidrivers storage.k8s.io false CSIDriver
csinodes storage.k8s.io false CSINode
storageclasses sc storage.k8s.io false StorageClass
volumeattachments storage.k8s.io false VolumeAttachment
kubectl delete
https://kubernetes.io/zh-cn/docs/reference/kubectl/generated/kubectl_delete/
选项
- –all: 删除指定资源类型的命名空间中的所有资源。
- -A, --all-namespaces: 如果存在,则列举所有命名空间中请求的对象。 即使使用 --namespace 指定,当前上下文中的命名空间也会被忽略。
- –dry-run string[=“unchanged”]: 必须是 “none”、“server” 或 “client”。如果是 client 策略,仅打印将要发送的对象,而不实际发送。 如果是 server 策略,提交服务器端请求而不持久化资源。默认值:“none”
- –field-selector string: 过滤所用的选择算符(字段查询),支持 ‘=’、‘==’ 和 ‘!=’。 (例如 --field-selector key1=value1,key2=value2)。服务器针对每种类型仅支持有限数量的字段查询。
- -f, --filename strings: 包含要删除的资源的文件名。
- –force: 如果为真,则立即从 API 中移除资源并略过体面删除处理。 请注意,立即删除某些资源可能会导致不一致或数据丢失,并且需要确认操作。
- –grace-period int: 指定给资源的体面终止时间(以秒为单位)。 如果为负数则忽略,为 1 表示立即关闭。 仅当 --force 为真(强制删除)时才可以设置为 0。默认值:-1
- -i, --interactive: 如果为 true,仅在用户确认时删除资源。
- –now: 如果为 true,资源将被标记为立即关闭(等同于 --grace-period=1)。
- -o, --output string: 输出模式。使用 “-o name” 以获得更简短的输出(resource/name)。
- -R, --recursive: 递归处理在 -f、–filename 中给出的目录。当你想要管理位于同一目录中的相关清单时很有用。
- -l, --selector string: 过滤所用的选择算符(标签查询),支持 ‘=’、‘==’ 和 ‘!=’。 (例如 -l key1=value1,key2=value2)。匹配的对象必须满足所有指定的标签约束。
- –timeout duration: 放弃删除之前等待的时间长度,为 0 表示根据对象的大小确定超时。
- –wait: 如果为 true,则等待资源消失后再返回。此参数会等待终结器被清空。默认值:true
# 删除pod
kubectl delete pods <pod>
# 使用 pod.json 中指定的类型和名称删除一个 Pod
kubectl delete -f ./pod.json
# 基于包含 kustomization.yaml 的目录(例如 dir/kustomization.yaml)中的内容删除资源
kubectl delete -k dir
# 删除所有以 '.json' 结尾的文件中的资源
kubectl delete -f '*.json'
# 基于传递到标准输入的 JSON 中的类型和名称删除一个 Pod
cat pod.json | kubectl delete -f -
# 删除名称为 "baz" 和 "foo" 的 Pod 和 Service
kubectl delete pod,service baz foo
# 删除打了标签 name=myLabel 的 Pod 和 Service
kubectl delete pods,services -l name=myLabel
# 以最小延迟删除一个 Pod
kubectl delete pod foo --now
# 仅在用户确认删除的情况下删除所有 Pod
kubectl delete pods --all --interactive
# 强制删除pod
kubectl delete pods <pod> --grace-period=0 --force
# 清除状态为Evicted的pod:
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
# 删除全部状态异常的pod:
kubectl delete pods $(kubectl get pods | grep -v Running | cut -d ' ' -f 1)
# 删除所有 Pod
kubectl delete pods --all
# 删除命名空间的所有资源(几乎)
kubectl delete all --all
kubectl logs
选项
- -c, --container=“”: 容器名。
- -f, --follow[=false]: 指定是否持续输出日志。
–interactive[=true]: 如果为true,当需要时提示用户进行输入。默认为true。
–limit-bytes=0: 输出日志的最大字节数。默认无限制。 - -p, --previous[=false]: 如果为true,输出pod中曾经运行过,但目前已终止的容器的日志。
–since=0: 仅返回相对时间范围,如5s、2m或3h,之内的日志。默认返回所有日志。只能同时使用since和since-time中的一种。
–since-time=“”: 仅返回指定时间(RFC3339格式)之后的日志。默认返回所有日志。只能同时使用since和since-time中的一种。
–tail=-1: 要显示的最新的日志条数。默认为-1,显示所有的日志。
–timestamps[=false]: 在日志中包含时间戳。
# 返回仅包含一个容器的pod nginx的日志快照
$ kubectl logs nginx
# 返回pod ruby中已经停止的容器web-1的日志快照
$ kubectl logs -p -c ruby web-1
# 持续输出pod ruby中的容器web-1的日志
$ kubectl logs -f -c ruby web-1
# 仅输出pod nginx中最近的20条日志
$ kubectl logs --tail=20 nginx
# 输出pod nginx中最近一小时内产生的所有日志
$ kubectl logs --since=1h nginx
kubectl label
更新(增加、修改或删除)资源上的 label(标签)
- label 必须以字母或数字开头,可以使用字母、数字、连字符、点和下划线,最长63个字符。
- 如果–overwrite 为 true,则可以覆盖已有的 label,否则尝试覆盖 label 将会报错。
- 如果指定了–resource-version,则更新将使用此资源版本,否则将使用现有的资源版本。
语法
#查看所有pod及labels
kubectl get pod --show-labels
#查看所有节点及labels
kubectl get nodes --show-labels
#删除节点的labels
kubectl label nodes <node-name> <label-key>-
#给节点添加labels
kubectl label nodes <node-name> <label-key>=<label-value>
#修改节点的labels
#需要加上--overwrite参数:
kubectl label nodes <node-name> <label-key>=<label-value> --overwrite
例子
#查询包含指定label的node节点
kubectl get nodes --show-labels -l "unhealthy=true"
#查询不包含指定label的pod资源
kubectl get pod -l '!unhealthy'
#给名为foo的Pod添加label unhealthy=true。
kubectl label pods foo unhealthy=true
#给名为foo的Pod修改label 为 'status' / value 'unhealthy',且覆盖现有的value。
kubectl label --overwrite pods foo status=unhealthy
#给 namespace 中的所有 pod 添加 label
kubectl label pods --all status=unhealthy
#仅当resource-version=1时才更新 名为foo的Pod上的label。
kubectl label pods foo status=unhealthy --resource-version=1
#删除名为“bar”的label 。(使用“ - ”减号相连)
kubectl label pods foo bar-
kubectl taint
语法
#给节点增加一个污点
kubectl taint nodes node1 key1=value1:NoSchedule
#移除上述命令所添加的污点
kubectl taint nodes node1 key1=value1:NoSchedule-
#查看所有节点上的污点信息
kubectl get nodes -o custom-columns=NAME:.metadata.name,Taints:.spec.taints
kubectl edit
# 编辑名为'docker-registry'的service:
kubectl edit svc/docker-registry
# 使用替代的编辑器
KUBE_EDITOR="nano" kubectl edit svc/docker-registry
# 编辑名为“myjob”的service,输出JSON格式 V1 API版本
kubectl edit job.v1.batch/myjob -o json
# 以YAML格式输出编辑deployment“mydeployment”,并将修改的配置保存在annotation中:
kubectl edit deployment/mydeployment -o yaml --save-config
生成yaml资源配置文件方法
#用run命令生成yaml文件
kubectl create deployment nginx --image=nginx:1.14 -o yaml --dry-run > my.deploy.yaml
#用get命令导出yaml文件
kubectl get deploy nginx-deployment -o yaml --export > mydeploy.yaml
#新版本--export已经被去除了,将--export删除即可
kubectl get deploy nginx-deployment -o=yaml > mydeploy.yaml
#Pod容器的字段拼写忘记了
kubectl explain pods.spec.containers
保存配置
kubectl apply <file.yaml> --save-config创建或更新部署,并将部署另存为元数据。
–save-config[=false]:如果为true,则当前对象的配置将保存在其注释中。当您将来要对此对象执行kubectl apply时,这非常有用。
#在 YAML 中编辑 deployment “mydeployment” ,并将修改后的配置保存在其注释中
kubectl edit deployment/mydeployment -o yaml --save-config
应用回滚
kubectl apply 每次更新应用时 Kubernetes 都会记录下当前的配置,保存为一个 revision(版次),这样就可以回滚到某个特定 revision。
默认配置下,Kubernetes 只会保留最近的几个 revision,可以在 Deployment 配置文件中通过 revisionHistoryLimit 属性增加 revision 数量。
使用也很简单,在更新的时候加上–record就可以了。
举个栗子
如下做两个httpd的yaml,分别为httpd.v1.yml,httpd.v2.yml,分别对应不同的 httpd 镜像 2.4.16,2.4.17:
##通过 kubectl apply 更新应用
kubectl apply -f httpd.v1.yml --record
kubectl apply -f httpd.v2.yml --record
##查看版本
kubectl rollout history deployment httpd
##设置服务滚动升级的速度,就是不要太快了
kubectl patch deployment httpd -p '{"spec": {"minReadySeconds": 10}}'
##执行升级操作,这里是将deployment中的image由2.4.17 改为 2.4.18
kubectl set image deployment httpd httpd=httpd/httpd:2.4.18
##回滚
kubectl rollout undo deployment httpd --to-revision=1
注意:
- record类似一个栈,先执行的apply会放到记录的最下端。也就是说你的上一个版本一定是2.
- record记录的是apply的命令,所以如果每次执行的命令是一样的话,会覆盖掉。
设置调度
官方文档:请点击此处
- 默认master是不能调度应用pod的。如果要允许master调度应用pod(即做master,也做为node节点使用)。可以使用如下命令:
# 将所有master做为node
$ kubectl taint nodes --all node-role.kubernetes.io/master-
node/k8s-master untainted
# 将指定master做为node,以下两个命令任选其一
$ kubectl taint nodes <NODE_NAME> node-role.kubernetes.io/master-
$ kubectl taint nodes <NODE_NAME> node-role.kubernetes.io/master:NoSchedule-
- 要恢复master仅做master,不做node,命令如下:
$ kubectl taint node <NODE_NAME> node-role.kubernetes.io/master="":NoSchedule
node/<NODE_NAME> tainted