每个node上只能运行一个副本:
apiVersion: extensions/v1beta1
kind: DaemonSet #使用DaemonSet的方式运行
metadata:
name: kube-flannel
namespace: kube-system
labels:
tier: node
app: flannel
spec:
template:
metadata:
labels:
tier: node
app: flannel
spec:
hostNetwork: true #指定pod直接使用的node网络,相当于docker run --network=host
nodeSelector:
beta.kubernetes.io/arch: amd64
containers: #以下定义了两个运行的容器
- name: kube-flannel
image: quay.io/coreos/flannel:v0.8.0-amd64
command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ]
- name: install-cni
image: quay.io/coreos/flannel:v0.8.0-amd64
command: [ "/bin/sh", "-c", "set -e -x;cp -f /etc/kube-flannel/cni-conf.json" ]
docker命令转换成yaml文件:
#docker运行命令
docker run -d \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
--net=host \
prom/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
#转换成DaemonSet的YAML配置文件
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: node-exporter
spec:
template:
metadata:
labels:
app: prometheus
spec:
hostNetwork: true #直接使用host网络
containers:
- name: node-exporter
image: prom/node-exporter
imagePullPolicy: IfNotPresent
command: #设置容器启动命令
- /bin/node_exporter
- --path.procfs
- /host/proc
- --path.sysfs
- /host/sys
- ^(sys|proc|dev|host|etc)($|/)
volumeMounts: #通过vloume将host路径/proc、/sys、/映射到容器中
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: root
mountPath: /rootfs
volumes:
- name: proc
hostPath:
path: /proc
- name: sys
hostPath:
path: /sys
- name: root
hostPath:
path: /