使用docker在k8s集群中部署grafana

grafana 镜像

直接到hub.docker.com上面拉一个官方最新的吧,当然也可以手动做一个。


docker pull grafana/grafana
docker tag grafana/grafana:latest 192.168.19.171/k8s/grafana:4.6.3
docker push 192.168.19.171/k8s/grafana:4.6.3

在K8S集群上面部署grafana

k8s集群版本为1.6.0

grafana只是展示数据,本身自己的数据是比较少的,可以用nfs做持久化

在官方镜像中grafana的数据存放路径是:/var/lib/grafana

在提供nfs访问的host上创建目录并刷新nfs

在有kubectl的host上面执行下面的shell脚本

最后在局域网的DNS 上面解析ingress中的url

默认账号密码是admin admin

cat <<EOF | kubectl apply -f -
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: grafana-dm
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate  
  selector:
    matchLabels:
      name: grafana-dm
  template:
    metadata:
      labels:
        name: grafana-dm
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - name: grafana
        image: 192.168.19.171/k8s/grafana:4.6.3
        imagePullPolicy: Always
        livenessProbe:
          httpGet:
            path: /
            port: 3000
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        volumeMounts:
        - name: grafana-data
          mountPath:  /var/lib/grafana
          readOnly: false
        - name: tz-config
          mountPath: /etc/localtime
        ports:
        - containerPort: 3000
      volumes:
      - name: grafana-data
        nfs:
          server: 192.168.7.206
          path: /opt/grafana
      - name: tz-config
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
spec:
#  type: NodePort
  ports: 
    - port: 80
#      nodePort: 30091
      targetPort: 3000
      protocol: TCP
  selector:
    name: grafana-dm
    
---
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: grafana
spec:
  rules:
  - host: gra.zhph.lan
    http:
      paths:
      - path: /
        backend:
          serviceName: grafana
          servicePort: 80
EOF
posted @ 2018-01-27 16:27  长风七万里  阅读(390)  评论(0编辑  收藏  举报