K8S中安装grafana7.4.5
K8S中安装grafana7.4.5
1.1.1 准备镜像并推送到Harbor仓库
docker pull grafana/grafana:7.4.5
docker tag 286028304712 harbor.st.com/infra/grafana:v7.4.5
docker push harbor.st.com/infra/grafana:v7.4.5
准备目录
mkdir /data/k8s-yaml/grafana
cd /data/k8s-yaml/grafana
名称空间
kubectl create ns test
1.1.2 准备rbac资源清单
cat >rbac7.4.5.yaml <<'EOF'
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/cluster-service: "true"
name: grafana
rules:
- apiGroups:
- "*"
resources:
- namespaces
- deployments
- pods
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/cluster-service: "true"
name: grafana
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: grafana
subjects:
- kind: User
name: k8s-node
EOF
1.1.3 准备dp资源清单
cat >dp7.4.5.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grafana
name: grafana
name: grafana
namespace: test
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 7
selector:
matchLabels:
name: grafana
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: grafana
name: grafana
spec:
containers:
- name: grafana
image: harbor.st.com/infra/grafana:v7.4.5
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
protocol: TCP
volumeMounts:
- mountPath: /var/lib/grafana
name: data
imagePullSecrets:
- name: harbor
securityContext:
runAsUser: 0
volumes:
- nfs:
server: hdss7-200
path: /data/nfs-volume/grafana7.4.5
name: data
EOF
创建grafana数据目录
mkdir /data/nfs-volume/grafana7.4.5
1.1.4 准备svc资源清单
cat >svc7.4.5.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: test
spec:
ports:
- port: 3000
protocol: TCP
targetPort: 3000
selector:
app: grafana
EOF
1.1.5 准备ingress资源清单
cat >ingress7.4.5.yaml <<'EOF'
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: grafana
namespace: test
spec:
rules:
- host: grafana7.st.com
http:
paths:
- path: /
backend:
serviceName: grafana
servicePort: 3000
EOF
1.1.6 域名解析
vi /var/named/st.com.zone
grafana A 192.168.x.x
systemctl restart named
1.1.7 应用资源配置清单
kubectl apply -f http://k8s-yaml.st.com/grafana/rbac7.4.5.yaml
kubectl apply -f http://k8s-yaml.st.com/grafana/dp7.4.5.yaml
kubectl apply -f http://k8s-yaml.st.com/grafana/svc7.4.5.yaml
kubectl apply -f http://k8s-yaml.st.com/grafana/ingress7.4.5.yaml
1.2 浏览器访问验证
访问http://grafana.st.com,默认用户名密码admin/admin
进入后立即要求修改管理员密码
添加普罗米修斯数据源后,即可图形化监控K8S的数据了
Grafana Dashboard推荐使用编号315这个,非常专业。