kubernetes-handbook/concepts/daemonset.md

144 lines
3.7 KiB
Markdown
Raw Normal View History

2017-05-14 19:39:33 +08:00
# DaemonSet
2017-05-14 19:08:56 +08:00
DaemonSet保证在每个Node上都运行一个容器副本常用来部署一些集群的日志、监控或者其他系统管理程序。典型的应用常见包括
* 日志收集比如fluentdlogstash等
* 系统监控比如Prometheus Node ExportercollectdNew Relic agentGanglia gmond等
* 系统程序比如kube-proxy, kube-dns, glusterd, ceph等
使用Fluentd收集日志的例子
```yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: fluentd
spec:
template:
metadata:
labels:
app: logging
id: fluentd
name: fluentd
spec:
containers:
- name: fluentd-es
image: gcr.io/google_containers/fluentd-elasticsearch:1.3
env:
- name: FLUENTD_ARGS
value: -qq
volumeMounts:
- name: containers
mountPath: /var/lib/docker/containers
- name: varlog
mountPath: /varlog
volumes:
- hostPath:
path: /var/lib/docker/containers
name: containers
- hostPath:
path: /var/log
name: varlog
```
## 指定Node节点
DaemonSet会忽略Node的unschedulable状态有两种方式来指定Pod只运行在指定的Node节点上
- nodeSelector只调度到匹配指定label的Node上
- nodeAffinity功能更丰富的Node选择器比如支持集合操作
- podAffinity调度到满足条件的Pod所在的Node上
nodeSelector示例
```yaml
spec:
nodeSelector:
disktype: ssd
```
nodeAffinity示例
```yaml
metadata:
name: with-node-affinity
annotations:
scheduler.alpha.kubernetes.io/affinity: >
{
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/e2e-az-name",
"operator": "In",
"values": ["e2e-az1", "e2e-az2"]
}
]
}
]
}
}
}
another-annotation-key: another-annotation-value
```
podAffinity示例
```yaml
metadata:
name: with-pod-affinity
annotations:
scheduler.alpha.kubernetes.io/affinity: >
{
"podAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": [
{
"labelSelector": {
"matchExpressions": [
{
"key": "security",
"operator": "In",
"values": ["S1"]
}
]
},
"topologyKey": "failure-domain.beta.kubernetes.io/zone"
}
]
},
"podAntiAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": [
{
"labelSelector": {
"matchExpressions": [
{
"key": "security",
"operator": "In",
"values": ["S2"]
}
]
},
"topologyKey": "kubernetes.io/hostname"
}
]
}
}
spec:
...
```
## 静态Pod
除了DaemonSet还可以使用静态Pod来在每台机器上运行指定的Pod这需要kubelet在启动的时候指定manifest目录
2017-05-19 18:12:54 +08:00
```bash
2017-05-14 19:08:56 +08:00
kubelet --pod-manifest-path=<the directory>
```
然后将所需要的Pod定义文件放到指定的manifest目录中即可。
注意静态Pod不能通过API Server来删除但可以通过删除manifest文件来自动删除对应的Pod。