DeamonSetとは
- ReplicaSetと似てる
- 各ノードにPodを1つづつ確実に配置する
- ReplicaSetでは指定した数上がってればよくてどのノードで起動するかはk8sがよしなに決める
- 1ノードに2Podずつの配置もできる
- Podを配置したくないNodeがあるときはnodeSelector,Node Anti-Affinityを使う
コンフィグファイル
sample-ds.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<span class="na">apiVersion</span><span class="pi">:</span> <span class="s">apps/v1</span> <span class="na">kind</span><span class="pi">:</span> <span class="s">DaemonSet</span> <span class="na">metadata</span><span class="pi">:</span> <span class="na">name</span><span class="pi">:</span> <span class="s">sample-ds</span> <span class="na">spec</span><span class="pi">:</span> <span class="na">selector</span><span class="pi">:</span> <span class="na">matchLabels</span><span class="pi">:</span> <span class="na">app</span><span class="pi">:</span> <span class="s">sample-app</span> <span class="na">template</span><span class="pi">:</span> <span class="na">metadata</span><span class="pi">:</span> <span class="na">labels</span><span class="pi">:</span> <span class="na">app</span><span class="pi">:</span> <span class="s">sample-app</span> <span class="na">spec</span><span class="pi">:</span> <span class="na">containers</span><span class="pi">:</span> <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">nginx-container</span> <span class="na">image</span><span class="pi">:</span> <span class="s">nginx:1.12</span> |
deploy
1 |
kubectl apply -f sample-ds.yaml |
各ノードへきれいにばらけて配置される
ノードは2つ
1 |
kubectl get nodes |
出力結果
1 2 3 |
NAME STATUS ROLES AGE VERSION ip-172-16-109-200.ec2.internal Ready <none> 4h48m v1.11.10-eks-17cd81 ip-172-16-117-100.ec2.internal Ready <none> 4h48m v1.11.10-eks-17cd81 |
1 |
kubectl get pods sample-ds-sr6gh -o wide |
Podその1
1 2 3 4 5 |
NAME READY STATUS RESTARTS AGE IP sample-ds-sr6gh 1/1 Running 0 112s 172.16.112.125 NODE NOMINATED NODE READINESS GATES ip-172-16-117-100.ec2.internal <none> <none> |
Podその2
1 |
kubectl get pods sample-ds-txhrv -o wide |
1 2 3 4 5 6 |
NAME READY STATUS RESTARTS AGE IP sample-ds-txhrv 1/1 Running 0 2m46s 172.16.109.101 NODE NOMINATED NODE READINESS GATES ip-172-16-109-200.ec2.internal <none> <none> |