阿里雲容器服務DaemonSet實踐
DaemonSet 保證在每個 Node 上都運行一個容器副本,常用來部署一些集羣的日誌、監控或者其他系統管理應用。下面以日誌收集 fluentd 為例,看下如何使用阿里雲容器服務控制檯創建DaemonSet。
準備Kubernetes環境
在阿里雲容器服務控制檯中創建Kubernetes 集羣(1.11.5),3 master,3 worker
安裝fluentd
1、選擇應用->守護進程集->使用鏡像創建
填寫應用名稱,選擇部署集羣、命名空間,進入下一步
2、選擇鏡像並進行相應配置
注意:這裡掛載了配置項fluentd-conf,用來覆蓋鏡像中的默認配置,需要提前創建出來,內容如下:
apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-conf
namespace: kube-system
data:
td-agent.conf: |
<match fluent.**>
type null
</match>
<source>
type tail
path /var/log/containers/*.log
pos_file /var/log/es-containers.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag kubernetes.*
format json
read_from_head true
</source>
<filter kubernetes.**>
type kubernetes_metadata
verify_ssl false
</filter>
否則會遇到pod 啟動問題
[error]: config error file="/etc/td-agent/td-agent.conf" error="Invalid Kubernetes API v1 endpoint https://172.21.0.1:443/api: SSL_connect returned=1 errno=0 state=error: certificate verify failed"
3、設置更新策略
可以在高級配置中選擇升級方式:
- 滾動升級(RollingUpdate):更新 DaemonSet 模版後,自動刪除舊的 Pod 並創建新的 Pod
- 替換升級(OnDelete):更新模板後,只有手動刪除了舊的 Pod 後才會創建新的 Pod
4、指定節點調度
只選擇worker節點安裝。設置節點親和性如圖。
5、創建完成
點擊創建,可以看到創建成功。
6、問題排查與更新
按著上述步驟可以看到在3個worker節點分別起了對應的pod,但pod並沒有成功啟動。選擇其中的一個容器,查看一下日誌發現如下錯誤:
config error file="/etc/td-agent/td-agent.conf" error="Exception encountered fetching metadata from Kubernetes API endpoint: pods is forbidden: User cannot list pods at the cluster scope"
Google後發現需要設置ClusterRole
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluent-account
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: fluent-account
roleRef:
kind: ClusterRole
name: view
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: fluent-account
namespace: kube-system
創建成功後更新fluent-es 的yaml,編輯yaml,提交更新。
Pod啟動成功,日誌已經可以正常採集了。
總結
使用阿里雲容器服務控制檯支持方便的創建DaemonSet,歡迎使用體驗。https://cs.console.aliyun.com/
本文作者:來隨便逛逛
原文鏈接
更多技術乾貨敬請關注云棲社區知乎機構號:阿里云云棲社區 - 知乎
本文為雲棲社區原創內容,未經允許不得轉載。
推薦閱讀: