标签:yam VID 操作 代理 tor val gluster dea lin
DaemonSet 确保全部(或者一些)Node 上运行一个 Pod 的副本。当有 Node 加入集群时,也会为他们新增一
个 Pod 。当有 Node 从集群移除时,这些 Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod
使用 DaemonSet 的一些典型用法:
[root@k8s-master mnt]# cat daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: deamonset-example
labels:
app: daemonset
spec:
selector:
matchLabels:
name: deamonset-example
template:
metadata:
labels:
name: deamonset-example
spec:
containers:
- name: daemonset-example
image: wangyanglinux/myapp:v3
[root@k8s-master mnt]#
[root@k8s-master mnt]# vim daemonset.yaml [root@k8s-master mnt]# kubectl create -f daemonset.yaml daemonset.apps/deamonset-example created [root@k8s-master mnt]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES deamonset-example-tpdf8 1/1 Running 0 8s 10.244.2.21 k8s-node01 <none> <none> deamonset-example-xxt2z 1/1 Running 0 8s 10.244.1.23 k8s-node02 <none> <none> [root@k8s-master mnt]# curl 10.244.2.21 Hello MyApp | Version: v3 | <a href="hostname.html">Pod Name</a> [root@k8s-master mnt]# kubectl delete deamonset-example-tpdf8 error: resource(s) were provided, but no name, label selector, or --all flag specified [root@k8s-master mnt]# kubectl delete pod deamonset-example-tpdf8 pod "deamonset-example-tpdf8" deleted [root@k8s-master mnt]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES deamonset-example-vdzjp 1/1 Running 0 3s 10.244.2.22 k8s-node01 <none> <none> deamonset-example-xxt2z 1/1 Running 0 107s 10.244.1.23 k8s-node02 <none> <none>
删除以后,会重新创建一个。
指定Node节点
DaemonSet会忽略Node的unschedulable状态,有两种方式来指定Pod只运行在指定的Node节点上:
首先给Node打上标签
kubectl label nodes node-01 disktype=ssd
然后在daemonset中指定nodeSelector为disktype=ssd:
spec:
nodeSelector:
disktype: ssd
nodeAffinity目前支持两种:requiredDuringSchedulingIgnoredDuringExecution和preferredDuringSchedulingIgnoredDuringExecution,分别代表必须满足条件和优选条件。比如下面的例子代表调度到包含标签kubernetes.io/e2e-az-name并且值为e2e-az1或e2e-az2的Node上,并且优选还带有标签another-node-label-key=another-node-label-value的Node。
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/e2e-az-name
operator: In
values:
- e2e-az1
- e2e-az2
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
containers:
- name: with-node-affinity
image: gcr.io/google_containers/pause:2.0
podAffinity基于Pod的标签来选择Node,仅调度到满足条件Pod所在的Node上,支持podAffinity和podAntiAffinity。这个功能比较绕,以下面的例子为例:
apiVersion: v1
kind: Pod
metadata:
name: with-pod-affinity
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: security
operator: In
values:
- S1
topologyKey: failure-domain.beta.kubernetes.io/zone
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: security
operator: In
values:
- S2
topologyKey: kubernetes.io/hostname
containers:
- name: with-pod-affinity
image: gcr.io/google_containers/pause:2.0
除了DaemonSet,还可以使用静态Pod来在每台机器上运行指定的Pod,这需要kubelet在启动的时候指定manifest目录:
kubelet --pod-manifest-path=/etc/kubernetes/manifests
然后将所需要的Pod定义文件放到指定的manifest目录中。
注意:静态Pod不能通过API Server来删除,但可以通过删除manifest文件来自动删除对应的Pod。
标签:yam VID 操作 代理 tor val gluster dea lin
原文地址:https://www.cnblogs.com/dalianpai/p/12088118.html