k8s 部署 grafana

创建namespace

grafana-namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: ns-grafana

拉取镜像

swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/rancher/mirrored-grafana-grafana:10.3.3

grafana的Deployment

grafana-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  namespace: ns-grafana
spec:
  replicas: 1
  selector:
    matchLabels:
      task: monitoring
      name: grafana
  template:
    metadata:
      labels:
        task: monitoring
        name: grafana
    spec:
      # hostNetwork: true
      containers:
      - name: grafana
        image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/rancher/mirrored-grafana-grafana:10.3.3
        ports:
        - containerPort: 3000
          protocol: TCP

如果使用Service模式部署可以注释hostNetwork: true

grafana的Service

grafana-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-grafana
  name: grafana-service
  namespace: ns-grafana
spec:
  ports:
  - port: 80
    targetPort: 3000
    nodePort: 31880
    protocol: TCP
  selector:
    name: grafana
  type: NodePort

启动

kubectl apply -f grafana-namespace.yaml
kubectl apply -f .

查看

kubectl get pod -n ns-grafana
kubectl get svc -n ns-grafana

访问

http://10.0.2.12:31880

10.0.2.12为宿主机ip,31880为Service映射的port。默认登录账号密码 admin / admin

posted @ 2024-10-22 12:21  BUG弄潮儿  阅读(3)  评论(0编辑  收藏  举报