在GCE上设置环境变量(kubernetes)

时间:2016-01-14 02:11:54

标签: kubernetes google-kubernetes-engine

对于noob问题感到抱歉,但来自https://github.com/kubernetes/kubernetes/blob/release-1.1/docs/getting-started-guides/logging-elasticsearch.md 它说:

  

要使用Elasticsearch和Kibana进行群集日志记录,您应该设置   以下环境变量如下所示:

KUBE_LOGGING_DESTINATION=elasticsearch

我在哪里以及如何设置此Env Var?我在想我应该使用

gcloud container clusters create   

并传递选项,但没有选项...

2 个答案:

答案 0 :(得分:13)

正如Robert在回答中已经提到的,如果群集应该在Google Container Engine(GKE)上运行,则需要手动添加Elasticsearch / Kibana堆栈。使用此post中提供的信息,我能够使其执行以下步骤:

  1. 启动没有云记录的GKE群集

    gcloud container --project <PROJECT_ID> clusters create <CLUSTER_ID> --no-enable-cloud-logging
    
  2. 使用kubernetes DaemonSet为每个正在运行的节点添加一个已配置的流畅容器。

    kubectl create -f fluentd-es.yaml
    

    <强> fluentd-es.yaml

    apiVersion: extensions/v1beta1
    kind: DaemonSet
    metadata:
      name: fluentd-elasticsearch
      namespace: kube-system
      labels:
        app: fluentd-logging
    
    spec:
      template:
        metadata:
          labels:
            app: fluentd-es
        spec:
          containers:
          - name: fluentd-elasticsearch
            image: gcr.io/google_containers/fluentd-elasticsearch:1.15
            resources:
              limits:
                memory: 200Mi
              requests:
                cpu: 100m
                memory: 200Mi
            volumeMounts:
            - name: varlog
              mountPath: /var/log
            - name: varlibdockercontainers
              mountPath: /var/lib/docker/containers
              readOnly: true
          volumes:
          - name: varlog
            hostPath:
              path: /var/log
          - name: varlibdockercontainers
            hostPath:
              path: /var/lib/docker/containers
    
  3. 添加elasticsearch和kibana pods和服务。

    kubectl create -f es-controller.yaml
    kubectl create -f es-service.yaml
    kubectl create -f kibana-controller.yaml
    kubectl create -f kibana-service.yaml
    

    请注意以下kubernetes.io/cluster-service: "true"标签(现在 在原来的files)中已被删除。 在定义中使用此标签会导致正在运行的pod终止。

    <强> ES-controller.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: elasticsearch-logging-v1
      namespace: kube-system
      labels:
        k8s-app: elasticsearch-logging
        version: v1
    spec:
      replicas: 2
      selector:
        k8s-app: elasticsearch-logging
        version: v1
      template:
        metadata:
          labels:
            k8s-app: elasticsearch-logging
            version: v1
            kubernetes.io/cluster-service: "true"
        spec:
          containers:
          - image: gcr.io/google_containers/elasticsearch:1.8
            name: elasticsearch-logging
            resources:
              limits:
                cpu: 100m
              requests:
                cpu: 100m
            ports:
            - containerPort: 9200
              name: db
              protocol: TCP
            - containerPort: 9300
              name: transport
              protocol: TCP
            volumeMounts:
            - name: es-persistent-storage
              mountPath: /data
          volumes:
          - name: es-persistent-storage
            emptyDir: {}
    

    <强> ES-service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: elasticsearch-logging
      namespace: kube-system
      labels:
        k8s-app: elasticsearch-logging
        kubernetes.io/name: "Elasticsearch"
    spec:
      ports:
      - port: 9200
        protocol: TCP
        targetPort: db
      selector:
        k8s-app: elasticsearch-logging
    

    <强> kibana-controller.yaml

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

    <强> kibana-service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: kibana-logging
      namespace: kube-system
      labels:
        k8s-app: kibana-logging
        kubernetes.io/name: "Kibana"
    spec:
      ports:
      - port: 5601
        protocol: TCP
        targetPort: ui
      selector:
        k8s-app: kibana-logging
    
  4. 创建kubectl代理

    kubectl proxy
    
  5. 使用kibana观看您的日志

    http://localhost:8001/api/v1/proxy/namespaces/kube-system/services/kibana-logging/

答案 1 :(得分:3)

该文档适用于通过GCE的开源shell脚本启动集群的用户。目前,Google Container Engine不支持Elasticsearch作为群集创建命令的一部分。创建群集后,您可以手动将其添加到群集。