Day 18 利用 Kubernetes 建立 Prometheus Service

Kubernetes and Prometheus

安装 Kubernetes 及 建立丛集

https://ithelp.ithome.com.tw/articles/10244493

什麽是 Prometheus

https://www.metricfire.com/blog/what-is-prometheus/

部署 Prometheus & Grafana 监控丛集

环境:
Ubuntu 20.04
Kubernetes v1.15.6

https://ithelp.ithome.com.tw/articles/10248278

建立 Namespace

kubectl create ns kube-ops

建立 ConfigMap

prometheus-cm.yaml

apiVersion: v1       
kind: ConfigMap
metadata:
  name: prometheus-config
  namespace: kube-ops
data:
  prometheus.yml: |
    global: 
      scrape_interval: 15s 
      scrape_timeout: 15s 
    scrape_configs: 
    - job_name: 'prometheus'
      static_configs: 
      - targets: ['localhost:9090']

建立 Prometheus Deployment

prometheus-deploy.yaml

apiVersion: apps/v1        
kind: Deployment
metadata:
  labels:
    app: prometheus
  name: prometheus
  namespace: kube-ops
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      serviceAccountName: prometheus
      containers:
      - image: prom/prometheus:v2.21.0
        name: prometheus
        command: 
        - "/bin/prometheus"
        args: 
        - "--config.file=/etc/prometheus/prometheus.yml"
        - "--storage.tsdb.path=/prometheus"
        - "--storage.tsdb.retention=24h"
        - "--web.enable-lifecycle"
        ports: 
        - containerPort: 9090
          protocol: TCP 
          name: http
        volumeMounts:
        - mountPath: "/prometheus"
          subPath: prometheus
          name: data
        - mountPath: "/etc/prometheus"
          name: config-volume
        resources:
          requests:
            cpu: 100m
            memory: 512Mi
          limits: 
            cpu: 100m
            memory: 512Mi
      securityContext:
        runAsUser: 0
      volumes:
      - name: data
        emptyDir: {}
      - configMap:
          name: prometheus-config
        name: config-volume    

建立 ServiceAccount

prometheus-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus
  namespace: kube-ops

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata: 
  name: prometheus
rules:
- apiGroups:
  - ""
  resources: 
  - nodes
  - services
  - endpoints
  - pods
  - nodes/proxy
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources: 
  - configmaps
  - nodes/metrics
  verbs:
  - get
- nonResourceURLs:
  - /metrics
  verbs:
  - get

---

apiVersion: rbac.authorization.k8s.io/v1
kind:  ClusterRoleBinding
metadata:
  name: prometheus
subjects:
- kind: ServiceAccount
  name: prometheus
  namespace: kube-ops
roleRef:
  kind: ClusterRole
  name: prometheus
  apiGroup: rbac.authorization.k8s.io   

建立 Prometheus Service (NodePort)

prometheus-svc.yaml

apiVersion: v1       
kind: Service
metadata: 
  name: prometheus
  namespace: kube-ops
  labels:
    app: prometheus
spec: 
  selector: 
    app: prometheus
  type: NodePort 
  ports:
    - name: web 
      port: 9090
      targetPort: 9090
      nodePort: 31111
kubectl apply -f .

部署结果

root@MGCHUNG-2:/home/ubuntu# kubectl get svc -n kube-ops
NAME         TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
prometheus   NodePort   10.101.214.225   <none>        9090:31111/TCP   9m4s

<<:  Day 18 - 网页元素DOM-取得文字,数值和其他输入 - input,colorpicker,sliderbar

>>:  Day 21:开始来学资料系结:文字插值

Progressive Web App 推播协定 (26)

之前已经可以用後端的套件去实作推播的服务器,但那个套件实际上做了哪些事情? 金钥对 Applicat...

Core Web Vitals 的新指标 INP

在今年的 Google I/O 大会中,Google 介绍了一个名为 INP(Interaction...

Day1 研究AR的起因&初心(刚出新手村的萌新)

选择研究/探讨AR相关技术是因为希望未来可以做出一些很酷的东西,像Pokemon GO或是游戏王卡的...

Day 19 - 卷积神经网络 CNN (4)-Pooling layer & Activation Function

Pooling Layer 影像的spatial information不会因scale而消失,所以...

[ 卡卡 DAY 15 ] - React Native 页面导览 Navigation (下)

接下来要在页面上按下按钮跳页 以及按了左边 header icon 回上一页 正所谓有去有回才不会...