Operator mode
Operator is an extension of Kubernetes, which utilizes custom resource management applications and their components. Operator follows the philosophy of Kubernetes, especially in terms of controllers .
Operator scenarios are specifically designed for stateful applications.
Why is it only for stateful apps?
Because the stateless application is simple and there is no interaction between services, you have to open another hot pot restaurant and tell k8s to open the same one.
There are differences in status. After you open a hot pot restaurant, how to synchronize customer information will involve negotiations with other hot pot restaurants. Of course, you can also write individual programs to do this data synchronization operation.
But what the operator does is to automatically recognize the asymmetry of the hot pot restaurant customer information and synchronize it actively. You only need to tell the operator that I want to open another chain hot pot restaurant.
Operator on Kubernetes
Kubernetes was born for automation. Without any modification, you can get many built-in automation functions from the Kubernetes core. You can use Kubernetes to automate the deployment and operation of workloads, and even automate Kubernetes itself.
The Kubernetes controller allows you to extend the behavior of the cluster without modifying the code of Kubernetes itself. Operator is a client of the Kubernetes API, acting as a controller for custom resources
Official website document: https://kubernetes.io/zh/docs/concepts/extend-kubernetes/operator/
Deploy prometheus
1.1, download
git clone -b release-0.7 --single-branch https://github.com/coreos/kube-prometheus.git
1.2, install operator
[root@k8s-master01 ~]# cd /root/kube-prometheus/manifests/setup
[root@k8s-master01 setup]# kubectl create -f .
# 查看是否Running
[root@k8s-master01 ~]# kubectl get pod -n monitoring
NAME READY STATUS RESTARTS AGE
prometheus-operator-848d669f6d-bz2tc 2/2 Running 0 4m16s
1.3, install Prometheus
[root@k8s-master01 ~]# cd /root/kube-prometheus/manifests
[root@k8s-master01 manifests]# kubectl create -f .
1.4, create ingress
[root@k8s-master01 manifests]# cat svc-ingress.yal
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: prom-ingresses
namespace: monitoring
spec:
rules:
- host: alert.test.com
http:
paths:
- backend:
serviceName: alertmanager-main
servicePort: 9093
path: /
- host: grafana.test.com
http:
paths:
- backend:
serviceName: grafana
servicePort: 3000
path: /
- host: prom.test.com
http:
paths:
- backend:
serviceName: prometheus-k8s
servicePort: 9090
path: /
[root@k8s-master01 manifests]# kubectl get ingress -n monitoring
NAME CLASS HOSTS ADDRESS PORTS AGE
prom-ingresses <none> alert.test.com,grafana.test.com,prom.test.com 10.96.107.62 80 23h