prometheus 安装部署
kube-prometheus-stack
https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack
https://kubernetes.github.io/ingress-nginx/deploy/#quick-start
https://github.com/kubernetes/ingress-nginx
安装 helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
安装 ingress-nginx
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--set controller.service.type=ClusterIP \
--set controller.kind=DaemonSet \
--set controller.hostNetwork=true \
--set controller.image.digest="" \
--set controller.admissionWebhooks.patch.image.digest="" \
--set controller.ingressClassResource.default=true
安装 kube-prometheus-stack
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm upgrade --install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
-n monitoring --create-namespace \
--set prometheus.ingress.enabled=true \
--set prometheus.ingress.hosts={prometheus.k8s.local} \
--set prometheus.ingress.paths={/} \
--set prometheus.ingress.pathType=Prefix \
--set alertmanager.ingress.enabled=true \
--set alertmanager.ingress.hosts={alertmanager.k8s.local} \
--set alertmanager.ingress.paths={/} \
--set alertmanager.ingress.pathType=Prefix \
--set grafana.ingress.enabled=true \
--set grafana.ingress.hosts={grafana.k8s.local} \
--set grafana.ingress.paths={/} \
--set grafana.ingress.pathType=Prefix \
--set grafana.adminPassword=admin
prometheus-operator
branch="release-0.11"
namespace=monitoring
domain="example.com"
git clone -b ${branch} https://github.com/prometheus-operator/kube-prometheus.git --depth 1
cd kube-prometheus
kubectl apply --server-side -f manifests/setup
kubectl wait \
--for condition=Established \
--all CustomResourceDefinition \
--namespace=${namespace}
kubectl apply -f manifests/
kubectl -n ${namespace} patch svc prometheus-k8s -p '{"spec":{"type":"NodePort"}}'
kubectl -n ${namespace} patch svc grafana -p '{"spec":{"type":"NodePort"}}'
kubectl -n ${namespace} patch svc alertmanager-main -p '{"spec":{"type":"NodePort"}}'
kubectl create ingress grafana.${domain} -n ${namespace} --class=nginx \
--rule="grafana.${domain}/*=grafana:3000"
kubectl create ingress prometheus.${domain} -n ${namespace} --class=nginx \
--rule="prometheus.${domain}/*=prometheus-k8s:9090"
# kubectl delete networkpolicy --all -n monitoring
# 查看 monitoring 命名空间下所有的镜像
kubectl get pods -n ${namespace} -o=jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | grep -v '<none>' | sort | uniq
# 保存 monitoring 命名空间下所有的镜像
docker save $( kubectl get pods -n ${namespace} -o=jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | grep -v '<none>' | sort | uniq ) -o kube-prometheus-${branch}.tar