上节我们安装了一个部署工具 kubeadm ,
部分内容来自课程
默认情况下 Master 节点是不允许运行用户 Pod 的。而 Kubernetes 做到这一点,依靠的是 Kubernetes 的 Taint/Toleration 机制。它的原理非常简单:一旦某个节点被加上了一个 Taint,即被“打上了污点”,那么所有 Pod 就都不能在这个节点上运行,因为 Kubernetes 的 Pod 都有“洁癖”。除非,有个别的 Pod 声明自己能“容忍”这个“污点”,即声明了 Toleration,它才可以在这个节点上运行。其中,为节点打上“污点”(Taint)的命令是:
$ kubectl taint nodes node1 foo=bar:NoSchedule
这时,该 node1 节点上就会增加一个键值对格式的 Taint,即:foo=bar:NoSchedule。其中值里面的 NoSchedule,意味着这个 Taint 只会在调度新 Pod 时产生作用,而不会影响已经在 node1 上运行的 Pod,哪怕它们没有 Toleration。
那么 Pod 又如何声明 Toleration 呢?
我们只要在 Pod 的.yaml 文件中的 spec 部分,加入 tolerations 字段即可:
apiVersion: v1
kind: Pod
...
spec:
tolerations:
- key: "foo"
operator: "Equal"
value: "bar"
effect: "NoSchedule"
这个 Toleration 的含义是,这个 Pod 能“容忍”所有键值对为 foo=bar 的 Taint( operator: “Equal”,“等于”操作)。现在回到我们已经搭建的集群上来。这时,如果你通过 kubectl describe 检查一下 Master 节点的 Taint 字段,就会有所发现了:
$ kubectl describe node master Name: master Roles: master Taints: node-role.kubernetes.io/master:NoSchedule
这里我们先放出我们的 yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
安装 pod 的时候我们执行的命令是 :
$ kubectl apply -f nginx-deployment.yaml
这个命令在创建 pod 的时候执行,执行的是创建的动作,如果我们想对 pod 进行修改,例如
...
spec:
containers:
- name: nginx
image: nginx:1.8 # 这里被从 1.7.9 修改为 1.8
ports:
- containerPort: 80
那么上面的命令执行的是更新的操作.
$ kubectl exec -it nginx-deployment-5c678cfb6d-lg9lw -- /bin/bash # ls /usr/share/nginx/html
$ kubectl delete -f nginx-deployment.yaml
深入剖析Kubernetes课程原文:https://www.cnblogs.com/Benjious/p/14773593.html