[TOC]
# DaemonSet
### 用途
用来确保每个节点(或者指定部分节点),在节点上运行一个Pod副本,这个副本随着节点的加入,自动创建;若节点被移除,Pod也将会被移除。
**应用场景:**
* 运行集群分布式存储,例如在每个 Node 上运行 glusterd、ceph节点
* 在每个 Node 上运行日志收集 daemon,例如fluentd、logstash
* 在每个 Node 上运行监控 daemon,例如 Prometheus Node
### 组成结构详解
~~~
##########常规字段,省略了############
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: example
namespace: kube-system
#####################################
#===========Pod模版部分===============
spec:
selector: #如果指定了 .spec.selector,必须与.spec.template.metadata.labels 相匹配
matchLabels:
name: example
#matchExpressions:这个可以自定义更加复杂的Selector
#key: value
#如果 matchLabels 和 matchExpressions 都指定,
#则两个结果之间为 AND 关系
template: # 必填字段
metadata:
labels:
name: example
#这里的labels 必须要和 .spec.selector相匹配,
#这个例子中,都是 name: example
#++++++++++++部署容器设置部分++++++++++++++
spec:
containers:
- name: fluentd-elasticsearch
image: k8s.gcr.io/fluentd-elasticsearch:1.20
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
~~~
### 调度节点的选择
一共分为三种方式选择调度节点:
* nodeSelector 根据 Node label 调度指定节点
* nodeAffinity 多种条件判断调度,支持集合操作
* podAffinity 调度到可以满足Pod条件的节点上
#### nodeSelector方式
首先给node打上标签
~~~
kubectl label nodes node-01 disktype=ssd
~~~
指定调度到 disktype=ssd 的节点
~~~
spec:
nodeSelector:
disktype: ssd
~~~
#### nodeAffinity方式
nodeAffinity提供两种条件选择方式:
* 必须满足条件 requiredDuringSchedulingIgnoredDuringExecution
* 优选条件 preferredDuringSchedulingIgnoredDuringExecution
##### 示例
调度到包含标签key-1并且值为aaa或bbb的Node上**并且**优选带有标签key-2=ccc的Node(权重+1)
~~~
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: key-1
operator: In
values:
- aaa
- bbb
preferredDuringSchedulingIgnoredDuringExecution:
#可以设置多个优选条件,不同的优选条件可以设置不一样的权重
- weight: 1
preference:
matchExpressions:
- key: key-2
operator: In
values:
- ccc
containers:
- name: with-node-affinity
image: gcr.io/google_containers/pause:2.0
~~~
#### podAffinity方式
podAffinity 提供两种条件选择方式:
* 调度到某一条件的节点 podAffinity
* 不调度到某一条件的节点 podAntiAffinity
##### 示例
* 如果一个 “ Node所在Zone中包含至少一个带有security=S1标签且运行中的Pod ” ,那么可以调度到该Node
* 不调度到“包含至少一个带有security=S2标签且运行中Pod”的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
~~~
- 一、K8S的安装
- 1.1 安装环境
- 1.2 问题汇总
- 1.3 事前准备
- 1.4 安装配置负载均衡
- 1.5 安装K8S软件
- 1.6 初始化kubeadm
- 1.7 添加控制节点
- 1.8 添加计算节点
- 1.9 安装故障问题处理
- 1.10 安装管理dashboard
- 1.11 编写测试Pod
- 1.12 从外部访问集群中的Pod
- 1.13 部署metrics-server指标采集
- 二、Pod管理
- 2.1 Pod 资源需求和限制
- 2.2 Init 容器
- 2.3 Pod 健康检查(探针)和重启策略
- 2.4 Pod 生命周期(钩子Hook)
- 2.5 静态Pod
- 2.6 初始化容器(init container)
- 2.7 资源限制
- 三、资源控制器
- 3.1 Deployment
- 3.2 StatefulSet
- 3.3 DaemonSet
- 3.4 Job
- 3.5 定时任务
- 3.6 准入控制器
- 3.7 自动伸缩
- 3.8 ReplicaSet
- 四、存储
- 4.1 Secret 管理敏感信息
- 4.2 ConfigMap 存储配置
- 4.3 Volume
- 4.4 PV
- 4.5 PVC
- 4.6 StorageClass
- 4.7 暴露宿主机信息给Pod
- 五、服务Service
- 5.1 Service 资源
- 5.2 服务发现
- 5.3 服务暴露
- 5.4 Ingress 资源
- 5.5 Ingress 专题
- 5.6 traefik 2.X版本使用
- 六、认证、授权、准入控制
- 6.1 服务账户
- 6.2 LimitRange资源与准入控制器
- 6.3 ResourceQuota 资源与准入控制器
- 七、Helm
- 7.1 Helm 安装
- 八、 istio
- 8.1 istio 介绍
- 8.2 iotis 安装
- 九、calico
- 9.1 两种网络模式
- 9.2 全互联模式 与 路由反射模式
- 9.3 BGP跨网段(大型网络)
- 十、Ingress
- 10.1 安装 LoadBalancer
- 10.2 部署 ingress-nginx
- 10.3 Ingress-nginx 的使用
- 10.4 开启TCP和UDP
- 使用中的问题
- CSI Node问题
