kubernetes部署grafana
1 min read

kubernetes部署grafana

创建标签
[root@k8s-master-01 grafana]# kubectl label node 192.168.9.28 app=grafana

编写grafana的yaml文件

[root@k8s-master-01 grafana]# cat deployment.yaml
---
apiVersion: v1
kind: Namespace
metadata:
  name: monitor
  
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: monitor
  labels:
    app: grafana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
      - image: grafana/grafana:latest
        name: grafana
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
          name: http
        env:
        - name: GF_SECURITY_ADMIN_USER
          value: admin
        - name: GF_SECURITY_ADMIN_PASSWORD
          value: xuetangX@2014
        readinessProbe:
          failureThreshold: 10
          httpGet:
            path: /api/health
            port: 3000
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 30
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /api/health
            port: 3000
            scheme: HTTP
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            cpu: 500m
            memory: 1024Mi
          requests:
            cpu: 100m
            memory: 256Mi
      nodeSelector:
        app: grafana
      volumes:
        - name: grafana-storage
          emptyDir: {}
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534
        fsGroup: 472


---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: monitor
  labels:
    app: grafana
spec:
  type: NodePort
  ports:
  - port: 3000
  selector:
    app: grafana

启动grafana
[root@k8s-master-01 grafana]# kubectl apply -f deployment.yaml

[root@k8s-master-01 grafana]# kubectl get rs -n monitor
NAME                 DESIRED   CURRENT   READY   AGE
grafana-75476c4d45   1         1         1       2m4s
nginx-64cccc97fb     0         0         0       24h
nginx-6cddc97554     2         2         2       24h

[root@k8s-master-01 grafana]# kubectl get deployment -n monitor
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
grafana   1/1     1            1           2m9s
nginx     2/2     2            2           24h

[root@k8s-master-01 grafana]# kubectl get svc -n monitor
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
grafana      NodePort    10.10.10.98   <none>        3000:40358/TCP   2m14s
kubernetes   ClusterIP   10.10.10.1    <none>        443/TCP          47h
nginx        ClusterIP   10.10.10.50   <none>        80/TCP           24h

[root@k8s-master-01 grafana]# kubectl get pods -n monitor
NAME                       READY   STATUS    RESTARTS   AGE
grafana-75476c4d45-dv28n   1/1     Running   0          2m22s
nginx-6cddc97554-qvjnr     1/1     Running   1          3h17m
nginx-6cddc97554-z92x2     1/1     Running   1          3h17m

验证:
在浏览器输入:http://192.168.9.29:40358

京ICP备19055754号