reidis-exporter服务需要用到configmap、service、deployment服务
创建存放yaml目录
mkdir?/opt/redis-exporter && cd?/opt/redis-exporter
编辑yaml配置文件
vi configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-conf
namespace: monitor
labels:
app: redis-exporter
data:
redis_passwd.json: |- #填写各redis节点地址端口和密码
{
"redis://10.1.60.17:6379":"12345678",
"redis://10.1.60.18:6379":"12345678",
"redis://10.1.60.19:6379":"12345678"
}
vi deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
app: redis-exporter
name: redis-exporter
namespace: monitor
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: redis-exporter
template:
metadata:
labels:
app: redis-exporter
spec:
containers:
- name: redis-exporter
image: oliver006/redis_exporter
imagePullPolicy: IfNotPresent
args:
- --redis.password-file=/redis_passwd.json
volumeMounts:
- mountPath: /etc/localtime
name: tz-config
- mountPath: /redis_passwd.json
name: redis-conf-volume
subPath: redis_passwd.json #使用subPath方式挂载配置文件
ports:
- containerPort: 9121
protocol: TCP
volumes:
- name: tz-config #挂载时间配置,与宿主机配置时间同步
hostPath:
path: /usr/share/zoneinfo/PRC
- name: redis-conf-volume #通过configmap挂载prometheus配置
configMap:
name: redis-conf
vi service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: redis-exporter
name: redis-exporter
namespace: monitor
spec:
type: NodePort
ports:
- name: http
port: 9121
targetPort: 9121
nodePort: 30012
selector:
app: redis-exporter
创建各yaml服务
kubectl apply -f?configmap.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
查看redis-exporter pod是否正常运行
kubectl get pod -n monitor