k8s学习(十一)创建DaemonSet
目录前言一、下载 fluentd-elasticsearch二、创建 DaemonSet三、版本回退四、指定 Node 节点前言DaemonSet 保证在每个 Node 上都运行一个容器副本,常用来部署一些集群的日志、监 控或者其他系统管理应用。应用场景: 在每个节点上运行集群的存储守护进程,例如kube-proxy,、kube-dns、gluster
前言
DaemonSet 保证在每个 Node 上都运行一个容器副本,常用来部署一些集群的日志、监 控或者其他系统管理应用。
应用场景:
在每个节点上运行集群的存储守护进程,例如kube-proxy,、kube-dns、glusterd、ceph
在每个节点上运行日志收集守护进程,例如 fluentd、logstash
在每个节点上运行监控守护进程,例如 Prometheus Node Exporter (opens new window)、Sysdig Agent (opens new window)、collectd、Dynatrace OneAgent (opens new window)、APPDynamics Agent (opens new window)、Datadog agent (opens new window)、New Relic agent (opens new window)、Ganglia gmond、Instana Agent (opens new window)等
一、下载 fluentd-elasticsearch
(1)查询 fluentd-elasticsearch
[root@k8s-master k8s]# docker search fluentd-elasticsearch
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
openfirmware/fluentd-elasticsearch fluentd setup to use the elastic search plug… 5 [OK]
oosidat/fluentd-elasticsearch-container Docker fluentd container to forward logs fro… 3 [OK]
ist0ne/fluentd-elasticsearch https://gcr.io/google_containers/fluentd-ela… 3 [OK]
kayrus/fluentd-elasticsearch 2
netonline/fluentd-elasticsearch k8s.gcr.io/fluentd-elasticsearch:v2.4.0 1 [OK]
forkdelta/fluentd-elasticsearch fluent/fluentd with fluent-plugin-elasticsea… 1 [OK]
vevo/fluentd-elasticsearch Docker image for sending Fluentd into Elasti… 1 [OK]
(2)下载
[root@k8s-master k8s]# docker pull ist0ne/fluentd-elasticsearch
Using default tag: latest
latest: Pulling from ist0ne/fluentd-elasticsearch
ee1a8002360e: Pull complete
c9d917eda150: Pull complete
6d38692b67e7: Pull complete
95a1871e425a: Pull complete
3663794ec44b: Pull complete
a7cb93690823: Pull complete
19104457e8cb: Pull complete
Digest: sha256:b563d0dd8037b6d5e0ce51f0ed204111ac8e9e84d44f300896550b38ae4fd285
Status: Downloaded newer image for ist0ne/fluentd-elasticsearch:latest
docker.io/ist0ne/fluentd-elasticsearch:latest
(3)打tag
docker tag ist0ne/fluentd-elasticsearch 172.16.10.158:80/ist0ne/fluentd-elasticsearch
(4)推送到仓库
[root@k8s-master k8s]# docker push 172.16.10.158:80/ist0ne/fluentd-elasticsearch
The push refers to repository [172.16.10.158:80/ist0ne/fluentd-elasticsearch]
1218b72d3db0: Pushed
66fb39ddd31b: Pushed
85c2f259a777: Pushed
b6a62dcf7b64: Pushed
71fa72fe86b4: Pushed
27dcf30dd611: Pushed
eb78099fbf7f: Pushed
latest: digest: sha256:b563d0dd8037b6d5e0ce51f0ed204111ac8e9e84d44f300896550b38ae4fd285 size: 1776
二、创建 DaemonSet
基于镜像 fluentd-elasticsearch 来创建 DaemonSet
(1)daemonset.yaml
[root@k8s-master k8s]# cat daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
app: fluentd-log
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: 172.16.10.158:80/fluentd-elasticsearch
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
(2)创建daemonset
[root@k8s-master k8s]# kubectl create -f daemonset.yaml
daemonset.apps/fluentd-elasticsearch created
(3)查看 fluentd-elasticsearch
[root@k8s-master k8s]# kubectl get ds -n kube-system | grep fluentd
fluentd-elasticsearch 2 2 0 2 0 <none> 114s
(4)查看pod
[root@k8s-master k8s]# kubectl get pods -n kube-system -o wide | grep fluentd
fluentd-elasticsearch-5fbwv 1/1 Running 0 3m 10.244.85.215 k8s-node01 <none> <none>
fluentd-elasticsearch-zkq9n 1/1 Running 0 2m58s 10.244.235.194 k8s-master <none> <none>
(5)查看daemonset详细信息
[root@k8s-master k8s]# kubectl describe ds fluentd-elasticsearch -n kube-system
Name: fluentd-elasticsearch
Selector: name=fluentd-elasticsearch
Node-Selector: <none>
Labels: app=fluentd-log
Annotations: deprecated.daemonset.template.generation: 2
Desired Number of Nodes Scheduled: 2
Current Number of Nodes Scheduled: 2
Number of Nodes Scheduled with Up-to-date Pods: 2
Number of Nodes Scheduled with Available Pods: 2
Number of Nodes Misscheduled: 0
Pods Status: 2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: name=fluentd-elasticsearch
Containers:
fluentd-elasticsearch:
Image: 172.16.10.158:80/ist0ne/fluentd-elasticsearch
Port: <none>
Host Port: <none>
Limits:
memory: 200Mi
Requests:
cpu: 100m
memory: 200Mi
Environment: <none>
Mounts:
/var/lib/docker/containers from varlibdockercontainers (ro)
/var/log from varlog (rw)
Volumes:
varlog:
Type: HostPath (bare host directory volume)
Path: /var/log
HostPathType:
varlibdockercontainers:
Type: HostPath (bare host directory volume)
Path: /var/lib/docker/containers
HostPathType:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 4m16s daemonset-controller Created pod: fluentd-elasticsearch-5fbwv
Normal SuccessfulCreate 4m14s daemonset-controller Created pod: fluentd-elasticsearch-zkq9n
三、版本回退
如果进行过升级,可以进行回归操作
(1)查询历史版本
[root@k8s-master k8s]# kubectl rollout history daemonset fluentd-elasticsearch -n kube-system
daemonset.apps/fluentd-elasticsearch
REVISION CHANGE-CAUSE
1 <none>
2 <none>
(2)查询某一版本详细信息
[root@k8s-master k8s]# kubectl rollout history daemonset fluentd-elasticsearch -n kube-system --revision=2
daemonset.apps/fluentd-elasticsearch with revision #2
Pod Template:
Labels: name=fluentd-elasticsearch
Containers:
fluentd-elasticsearch:
Image: 172.16.10.158:80/ist0ne/fluentd-elasticsearch
Port: <none>
Host Port: <none>
Limits:
memory: 200Mi
Requests:
cpu: 100m
memory: 200Mi
Environment: <none>
Mounts:
/var/lib/docker/containers from varlibdockercontainers (ro)
/var/log from varlog (rw)
Volumes:
varlog:
Type: HostPath (bare host directory volume)
Path: /var/log
HostPathType:
varlibdockercontainers:
Type: HostPath (bare host directory volume)
Path: /var/lib/docker/containers
HostPathType:
(3)回退版本
[root@k8s-master k8s]# kubectl rollout undo daemonset fluentd-elasticsearch -n kube-system --to-revision=1
daemonset.apps/fluentd-elasticsearch rolled back
(4)查看回退状态
[root@k8s-master k8s]# kubectl rollout status ds fluentd-elasticsearch -n kube-system
daemon set "fluentd-elasticsearch" successfully rolled out
四、指定 Node 节点
1、nodeSelector:基于Node的标签来选择Node,只调度到匹配指定label的Node上。
2、nodeAffinity:基于Node的标签来选择Node,功能更丰富的Node选择器,比如支持集合操作,nodeAffinity 目前支持两种:requiredDuringSchedulingIgnoredDuringExecution 和 preferredDuringSchedulingIgnoredDuringExecution,分别代表必须满足条件和优选条 件。
3、podAffinity:基于 Pod 的标签来选择 Node,调度到满足条件的Pod所在的Node上,仅调度到满足条件 Pod 所在的 Node 上,支 持 podAffinity 和 podAntiAffinity。
更多推荐
所有评论(0)