本文主要是介绍k8s部署alertmanager,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
修改alertmanager-pvc.yaml
文件中的信息,然后应用YAML文件
cat > /opt/k8s/alertmanager/alertmanager-pvc.yaml <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: alertmanager-data-pvc
spec:accessModes:- ReadWriteManystorageClassName: "nfs-storage"resources:requests:storage: 5Gi
EOF
kubectl apply -f alertmanager-pvc.yaml
kubectl get pvc
部署ConfigMap
上传文件alertmanager.yml 到/opt/k8s/alertmanager/file/下
kubectl create configmap alertmanager-config \--from-file=alertmanager.yml=/opt/k8s/alertmanager/file/alertmanager.yml
如需修改可使用kubectl edit 或者以下方式
删除现有的ConfigMap
kubectl delete configmap alertmanager-config
使用新的文件重新创建ConfigMap
kubectl create configmap alertmanager-config
–from-file=alertmanager.yml=/opt/k8s/alertmanager/file/alertmanager.yml
部署Deployment
修改alertmanager-Deployment.yaml
文件中的信息,然后应用YAML文件
cat > /opt/k8s/alertmanager/alertmanager-Deployment.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:name: alertmanager
spec:replicas: 1selector:matchLabels:app: alertmanagertemplate:metadata:labels:app: alertmanagerspec:containers:- name: alertmanagerimage: prom/alertmanager:v0.27.0args:- "--config.file=/etc/alertmanager/alertmanager.yml"ports:- containerPort: 9093volumeMounts:- name: alertmanager-storagemountPath: /alertmanager- name: alertmanager-configmountPath: /etc/alertmanager/alertmanager.ymlsubPath: alertmanager.ymlvolumes:- name: alertmanager-storagepersistentVolumeClaim:claimName: alertmanager-data-pvc- name: alertmanager-configconfigMap:name: alertmanager
EOF
kubectl apply -f alertmanager-Deployment.yaml
kubectl get Deployment
部署Service
修改alertmanager-Service.yaml
文件中的信息,然后应用YAML文件
cat > /opt/k8s/alertmanager/alertmanager-Service.yaml <<EOF
apiVersion: v1
kind: Service
metadata:name: alertmanager-service
spec:type: NodePortports:- port: 9093targetPort: 9093nodePort: 30093selector:app: alertmanager
EOF
kubectl apply -f alertmanager-Service.yaml
kubectl get Service
这篇关于k8s部署alertmanager的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!