各个节点都要操作
# 解压缩
docker load -i /root/k8s/monitor/kube-state-metrics_1_9_0.tar.gz
# 删除
rm -rf /root/k8s/monitor/kube-state-metrics_1_9_0.tar.gz
vi /root/k8s/monitor/kube-state-metrics-rbac.yaml
内容
# 创建sa
---
apiVersion: v1
kind: ServiceAccount
metadata:
# sa 账号名称
name: kube-state-metrics
# sa 账号名称空间
namespace: kube-system
---
# 对sa账号进行rbac授权
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kube-state-metrics
rules:
- apiGroups: [""]
resources: ["nodes", "pods", "services", "resourcequotas", "replicationcontrollers", "limitranges", "persistentvolumeclaims", "persistentvolumes", "namespaces", "endpoints"]
verbs: ["list", "watch"]
- apiGroups: ["extensions"]
resources: ["daemonsets", "deployments", "replicasets"]
verbs: ["list", "watch"]
- apiGroups: ["apps"]
resources: ["statefulsets"]
verbs: ["list", "watch"]
- apiGroups: ["batch"]
resources: ["cronjobs", "jobs"]
verbs: ["list", "watch"]
- apiGroups: ["autoscaling"]
resources: ["horizontalpodautoscalers"]
verbs: ["list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kube-state-metrics
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kube-state-metrics
subjects:
- kind: ServiceAccount
name: kube-state-metrics
namespace: kube-system
kubectl apply -f /root/k8s/monitor/kube-state-metrics-rbac.yaml
# 查看
kubectl get sa -n kube-system | grep metrics
vi /root/k8s/monitor/kube-state-metrics-deploy.yaml
内容
apiVersion: apps/v1
kind: Deployment
metadata:
# Deployment的名称和 使用的名称空间
name: kube-state-metrics
namespace: kube-system
spec:
# 副本实例
replicas: 1
# 标签选择器,选择哪个template
selector:
matchLabels:
app: kube-state-metrics
# 定义template
template:
metadata:
labels:
app: kube-state-metrics
# 定义容器
spec:
# sa账号
serviceAccountName: kube-state-metrics
containers:
- name: kube-state-metrics
# image: gcr.io/google_containers/kube-state-metrics-amd64:v1.3.1
image: quay.io/coreos/kube-state-metrics:v1.9.0
ports:
- containerPort: 8080
kubectl apply -f /root/k8s/monitor/kube-state-metrics-deploy.yaml
# 查看
kubectl get ConfigMap -n monitor-sa