创建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: grafananamespace: ns-grafana
spec:replicas: 1selector:matchLabels:task: monitoringname: grafanatemplate:metadata:labels:task: monitoringname: grafanaspec:# hostNetwork: truecontainers:- name: grafanaimage: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/rancher/mirrored-grafana-grafana:10.3.3ports:- containerPort: 3000protocol: TCP
如果使用Service模式部署可以注释hostNetwork: true
;
grafana的Service
grafana-service.yaml
apiVersion: v1
kind: Service
metadata:labels:kubernetes.io/cluster-service: 'true'kubernetes.io/name: monitoring-grafananame: grafana-servicenamespace: ns-grafana
spec:ports:- port: 80targetPort: 3000nodePort: 31880protocol: TCPselector:name: grafanatype: 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