EFK简单部署收集K8S日志

js 复制代码
docker pull  elasticsearch:8.11.0
docker pull kibana:8.11.0

mkdir -p /data/es/{config,data,plugins}
chmod 777 /data/es/{config,data,plugins}

cat > /data/es/config/elasticsearch.yml <<EOF
cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: false
EOF
安装ES
js 复制代码
docker run -d \
 --name elasticsearch \
 --network es-network \
 --restart=always \
 -p 9200:9200 \
 -p 9300:9300 \
 -v /data/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
 -v /data/es/data:/usr/share/elasticsearch/data \
 -v /data/es/plugins:/usr/share/elasticsearch/plugins \
 -e "discovery.type=single-node" \
 -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
 elasticsearch:8.11.0

kibana

js 复制代码
mkdir -p  /data/kibana/{config,data}
chmod 777 /data/kibana/{config,data}
cat > /data/kibana/config/kibana.yml << EOF
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
EOF
js 复制代码
docker run -d \
--name kibana \
--network es-network \
--restart=always \
-p 5601:5601 \
-v /data/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml \
kibana:8.11.0

K8S部署

js 复制代码
cat > fluentd.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: fluentd
  namespace: demon
  labels:
    app: fluentd
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: fluentd
  labels:
    app: fluentd
rules:
- apiGroups:
  - ""
  resources:
  - pods
  - namespaces
  verbs:
  - get
  - list
  - watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: fluentd
roleRef:
  kind: ClusterRole
  name: fluentd
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: fluentd
  namespace: demon
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: demon
  labels:
    app: fluentd
spec:
  selector:
    matchLabels:
      app: fluentd
  template:
    metadata:
      labels:
        app: fluentd
    spec:
      serviceAccount: fluentd
      serviceAccountName: fluentd
      tolerations:
      - key: node-role.kubernetes.io/control-plane
        effect: NoSchedule
      containers:
      - name: fluentd
        image: fluentd-kubernetes-daemonset:v1.16-debian-elasticsearch8-1
        imagePullPolicy: IfNotPresent
        env:
          - name:  FLUENT_ELASTICSEARCH_HOST
            value: "192.168.0.12"
          - name:  FLUENT_ELASTICSEARCH_PORT
            value: "9200"
          - name: FLUENT_ELASTICSEARCH_SCHEME
            value: "http"
          - name: FLUENTD_SYSTEMD_CONF
            value: disable
          - name: FLUENT_CONTAINER_TAIL_PARSER_TYPE
            value: "cri"
          - name: FLUENT_CONTAINER_TAIL_PARSER_TIME_FORMAT
            value: "%Y-%m-%dT%H:%M:%S.%L%z"
        resources:
          limits:
            memory: 4024Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: containers
          mountPath: /var/log/containers
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: containers
        hostPath:
          path: /var/log/containers
EOF


相关推荐
SRExianxian1 小时前
kubernetes存储架构之PV controller源码解读
容器·架构·kubernetes
lifeng43212 小时前
Jenkins集成部署(图文教程、超级详细)
运维·jenkins
cdg==吃蛋糕3 小时前
docker代理配置
docker·容器·eureka
ether-lin3 小时前
DevOps实战:用Kubernetes和Argo打造自动化CI/CD流程(2)
kubernetes·自动化·devops
web135085886354 小时前
使用docker compose安装gitlab
docker·容器·gitlab
IT机器猫4 小时前
Docker完整技术汇总
运维·docker·容器
董健正4 小时前
Docker安装
docker·容器·docker-compose
无所不在的物质4 小时前
Jenkins基础教程
运维·云原生·自动化·jenkins
coco_1998_25 小时前
nvidia docker, nvidia docker2, nvidia container toolkits区别
docker·容器
vvw&5 小时前
Docker Build 命令详解:在 Ubuntu 上构建 Docker 镜像教程
linux·运维·服务器·ubuntu·docker·容器·开源