阿里云sls日志收集logtail容器部署
作者:互联网
安装ilogtail
1.登陆可以控制K8S集群的中控机。编辑ilogtail的ConfigMap YAML。
$ vim alicloud-log-config.yaml
在Vim中粘贴如下内容并保存(注意,修改注释中提示的字段,7-11行)。
apiVersion: v1
kind: ConfigMap
metadata:
name: alibaba-log-configuration
namespace: kube-system
data:
log-project: "my-project" #修改为实际创建的project名称
log-endpoint: "cn-wulanchabu.log.aliyuncs.com" #修改为实际endpoint 改一下地区就可
log-machine-group: "my-k8s-group" #可以自定义机器组名称
log-config-path: "/etc/ilogtail/conf/cn-wulanchabu_internet/ilogtail_config.json" #修改cn-wulanchabu为实际project地域
log-ali-uid: "*********" #修改为阿里云UID在k8s集群详情中查看
access-key-id: "" #本教程用不上
access-key-secret: "" #本教程用不上
cpu-core-limit: "2"
mem-limit: "1024"
max-bytes-per-sec: "20971520"
send-requests-concurrency: "20"
2.计算alicloud-log-config.yaml的sha256 hash,并编辑ilogtail的DaemonSet YAML。
$ sha256sum alicloud-log-config.yaml
f370df37916797aa0b82d709ae6bfc5f46f709660e1fd28bb49c22da91da1214 alicloud-log-config.yaml
$ vim logtail-daemonset.yaml
在Vim中粘贴如下内容并保存(注意,修改注释中提示的字段,21、25行)。
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: logtail-ds
namespace: kube-system
labels:
k8s-app: logtail-ds
spec:
selector:
matchLabels:
k8s-app: logtail-ds
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
k8s-app: logtail-ds
kubernetes.io/cluster-service: "true"
version: v1.0
annotations:
checksum/config: f370df37916797aa0b82d709ae6bfc5f46f709660e1fd28bb49c22da91da1214 #必须修改为alicloud-log-config.yaml的hash
spec:
containers:
- name: logtail
image: registry.cn-wulanchabu.aliyuncs.com/log-service/logtail:latest #可以修改为距离k8s集群最近的地域
resources:
limits:
cpu: 2
memory: 1024Mi
requests:
cpu: 100m
memory: 256Mi
livenessProbe:
httpGet:
path: /liveness
port: 7953
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 60
securityContext:
privileged: true
env:
- name: HTTP_PROBE_PORT
value: "7953"
- name: "ALIYUN_LOGTAIL_CONFIG"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: log-config-path
- name: "ALIYUN_LOGTAIL_USER_ID"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: log-ali-uid
- name: "ALIYUN_LOGTAIL_USER_DEFINED_ID"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: log-machine-group
- name: "ALICLOUD_LOG_ACCESS_KEY_ID"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: access-key-id
- name: "ALICLOUD_LOG_ACCESS_KEY_SECRET"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: access-key-secret
- name: "ALICLOUD_LOG_DOCKER_ENV_CONFIG"
value: "true"
- name: "ALICLOUD_LOG_ECS_FLAG"
value: "false"
- name: "ALICLOUD_LOG_DEFAULT_PROJECT"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: log-project
- name: "ALICLOUD_LOG_ENDPOINT"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: log-endpoint
- name: "ALICLOUD_LOG_DEFAULT_MACHINE_GROUP"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: log-machine-group
- name: "ALIYUN_LOG_ENV_TAGS"
value: "node_name|node_ip"
- name: "node_name"
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: "node_ip"
valueFrom:
fieldRef:
fieldPath: status.hostIP
# resource limit for logtail self process
- name: "cpu_usage_limit"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: cpu-core-limit
- name: "mem_usage_limit"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: mem-limit
- name: "max_bytes_per_sec"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: max-bytes-per-sec
- name: "send_request_concurrency"
valueFrom:
configMapKeyRef:
name: alibaba-log-configuration
key: send-requests-concurrency
volumeMounts:
- name: sock
mountPath: /var/run/
- name: root
mountPath: /logtail_host
readOnly: true
mountPropagation: HostToContainer
terminationGracePeriodSeconds: 30
tolerations:
- operator: "Exists"
hostNetwork: true
dnsPolicy: "Default"
volumes:
- name: sock
hostPath:
path: /var/run/
- name: root
hostPath:
path: /
3.应用YAML配置,创建ConfigMap和DaemonSet。
$ kubectl apply -f alicloud-log-config.yaml
configmap/alibaba-log-configuration created
$ kubectl apply -f logtail-daemonset.yaml
daemonset.apps/logtail-ds created
4.等待1分钟,检查DeamonSet是否正常运行
$ kubectl get -f logtail-daemonset.yaml
这个时候控制台应该打印出类似以下的消息,代表安装成功
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
logtail-ds 3 3 3 3 3
标签:configuration,log,valueFrom,sls,key,日志,logtail,name 来源: https://www.cnblogs.com/wangyanfu/p/16419040.html