DaemonSet
DaemonSet sure to run a copy of the Pod on all (or some) Node. When Node joins the cluster, they will add one for
a Pod. When a Node is removed from the cluster, the Pod will be recovered. Delete DaemonSet will delete all Pod that it creates
some typical Usage DaemonSet of:
- Running clustered storage daemon, such as running glusterd on each Node, ceph
- Collecting log daemon running on each Node, e.g. fluentd, logstash
- On each Node operation monitoring daemon, e.g. Prometheus Node Exporter, collectd, Datadog agents, New Relic agent, or Ganglia gmond
[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>
After deleting, re-create one.
Designated Node node
DaemonSet ignored unschedulable state Node There are two ways to specify Pod run only on the specified Node node:
- nodeSelector: Only scheduled on the label matches the specified Node
- nodeAffinity: more feature-rich Node selector, such as support for set operations
- Node scheduling the Pod meeting the conditions where: podAffinity
nodeSelector example
First to tag the Node
kubectl label nodes node-01 disktype=ssd
And then specify the nodeSelector daemonset is disktype = ssd:
spec:
nodeSelector:
disktype: ssd
nodeAffinity example
nodeAffinity currently supports two: requiredDuringSchedulingIgnoredDuringExecution and preferredDuringSchedulingIgnoredDuringExecution, representing the conditions and preferred conditions must be met. Representative examples such as the following schedule to include a label and kubernetes.io/e2e-az-name value or the Node e2e-az1 e2e-az2, and preferably also with the tag another-node-label-key = another-node- label-value of 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 example
Pod podAffinity based label selected Node, the Node scheduling only to satisfy the condition where the Pod, and support podAffinity podAntiAffinity. This function is relatively around, as an example in the following examples:
- If a "Node is located in Zone comprises at least one security = S1 and the operation of the tag with a Pod", it can be scheduled to the Node
- Not scheduled "comprising at least one label and with security = S2 Pod operation" on the Node
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
Static Pod
In addition to DaemonSet, you can also use static Pod to run on each machine specified in the Pod, which requires kubelet manifest specified directory at startup:
kubelet --pod-Manifest-path = / etc / kubernetes / Manifests
Then the required Pod definition file into the directory specified in the manifest.
Note: Static Pod API Server can not be deleted, but can be automatically deleted by deleting the corresponding Pod manifest file.