美文网首页
五.Kubernetes实践指南--Kubernetes高级案列

五.Kubernetes实践指南--Kubernetes高级案列

作者: 何何与呵呵呵 | 来源:发表于2019-12-18 09:26 被阅读0次
ElasticSearch日志搜集查询
  • Fluentd+ElasticSearch+Kibana
架构图

1.创建elasticsearch-rc-svc.yml

apiVersion: v1
kind: ReplicationController
metadata:
  name: es-logging-v1
  namespace: kube-system
  labels:
    k8s-app: es-logging
    version: v1
    kebernetes.io/cluster-service: "true"
spec:
  replicas: 2
  selector:
    k8s-app: es-logging
    version: v1
  template:
    metadata:
      labels:
        k8s-app: es-logging
        version: v1
        kebernetes.io/cluster-service: "true"
      spec:
        containers:
        - image: gcr.io/google_containers/elasticsearch:1.8 ## 对应容器
          name: es-logging ## 容器名字
          resources:
            limits:
              cpu: 100m
            requests:
              cpu: 100m
          ports:
          - containerPort: 9200 ## 容器启动端口
            name: db
            protocol: TCP
          - containerPort: 9300
            name: transport
            protocol: TCP
          volumeMounts: ## 容器使用,安装到/data目录
          - name: es-persistent-storage
            mountPath: /data
        volumes: ## 定义挂载卷,给容器使用
        - name: es-persistent-storage
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: es-logging
  namespace: kube-system
  labels:
    k8s-app: es-logging
    kebernetes.io/cluster-service: "true"
    kebernetes.io/name: "Elasticsearch"
spec:
  ports:
  - port: 9200 ##service的虚端口
    protocol: TCP
    targetPort: db ##提供服务容器暴露的端口号
  selector:
    k8s-app: es-logging

2.创建 fluentd-ds.yml

apiVersion: extensions/v1beta1
kind: DaemonSet ##确保每个node上有一个副本
metadata:
  name: fluentd-cloud-logging
  namespace: kube-system
  labels:
    k8s-app: fluentd-cloud-logging
spec:
  template:
    metadata:
      namespace: kube-system
      labels:
        k8s-app: fluentd-cloud-logging
      spec:
        containers:
        - image: gcr.io/google_containers/fluentd-elasticsearch:1.17
          name: fluentd-cloud-logging
          resources:
            limits:
              cpu: 100m
              memory: 200m
          env: ## 环境变量
          - name: FLUENTD_ARGS
            value: -q
          volumeMounts:
          - name: varlog
            mountPath: /var/log
            readOnly: false
        volumes:
        - name: containers
          hostPath:
            path: /var/lib/docker/containers
        - name: varlog
          hostPath:
            path: /var/log

3.运行Kibana,创建kibana-rc-svc.yml

apiVersion: v1
kind: ReplicationController
metadata:
  name: kibana-logging-v1
  namespace: kube-system
  labels:
    k8s-app: kibana-logging
    version: v1
    kebernetes.io/cluster-service: "true"
spec:
  replicas: 1
  selector:
    k8s-app: kibana-logging
    version: v1
  template:
    metadata:
      labels:
        k8s-app: kibana-logging
        version: v1
        kebernetes.io/cluster-service: "true"
      spec:
        containers:
          - image: gcr.io/google_containers/kibana:1.3
            name: kibana-logging
            resources:
              limits:
                cpu: 100m
              requests:
                cpu: 100m
            env:
              - name: "ELASTICSEARCH_URL"
                value: "http://elasticsearch-logging:9200"
            ports:
              - containerPort: 5601
                name: ui
                protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: kibina-logging
  namespace: kube-system
  labels:
    k8s-app: kibina-logging
    kebernetes.io/cluster-service: "true"
    kebernetes.io/name: "Kibana"
spec:
  ports:
  - port: 5601
    protocol: TCP
    targetPort: ui
  selector:
    k8s-app: kibana-logging

相关文章

网友评论

      本文标题:五.Kubernetes实践指南--Kubernetes高级案列

      本文链接:https://www.haomeiwen.com/subject/hvgzgctx.html