Te aro turuki me te taki i nga ratonga o waho ki te roopu Kubernetes

Te aro turuki me te taki i nga ratonga o waho ki te roopu Kubernetes

Waimarie ki te katoa.

Kare ano au i kite i tetahi aratohu whanui i runga ipurangi mo te takiuru me te kohi inenga mai i nga ratonga tuatoru ki roto i nga punaha kua horahia ki roto. Kubernetes. Kei te tuku ahau i taku otinga. Ko tenei tuhinga e kii ana kua whai mahi koe Prometheus me etahi atu ratonga. Hei tauira mo te puna raraunga mo te ratonga ahua o waho, ka whakamahia he DBMS PostgreSQL i roto i te ipu Docker. Ka whakamahia e te kamupene he kaiwhakahaere putea Helm, kei raro iho i roto i te tuhinga he tauira kei runga. Mo te otinga katoa, kei te whakareri matou i ta matou ake tūtohi, kei roto ko nga tūtohi kohanga o nga ratonga katoa e whakamahia ana.

Te takiuru

He maha nga kamupene e whakamahi ana i nga momo hangarau ki te kohikohi, ki te tiro me te whakauru i nga raarangi Te rangahau elastic + Te whanui + kibana, whakapotohia hei ELK. I roto i a maatau, kaore he take ki te tohu i nga ihirangi ka whakamahia e au he maamaa ake Loki. Kei te waatea hei kete Helm, i taapirihia e matou hei raarangi iti ma te whakarereke i nga uara mo te whakauru me te pv kia pai ki ta maatau punaha.

uara.yaml

ingress:
  enabled: true
  annotations:
     kubernetes.io/ingress.class: nginx
  hosts:
    - host: kube-loki.example.domain
      paths: 
        - /
  tls: []

....

persistence:
  type: pvc
  enabled: true
  accessModes:
    - ReadWriteOnce
  size: 100Gi
  finalizers:
    - kubernetes.io/pvc-protection
  existingClaim: "pv-loki"

Hei tuku rangitaki ki tetahi tauira Loki используем Loki Docker Takitaki Atekōkiri.

Me whakauru koe i tenei taapiri ki runga i nga mea katoa Docker nga kaihautu e hiahia ana koe ki te tango i nga raarangi. He maha nga huarahi ki te korero ki te daemon me pehea te whakamahi i te papa. Ka tohua e ahau te taraiwa i te yaml Whakaritea e Docker, he wahanga Ka taea pukapuka takaro.

postgres.yaml

    - name: Run containers
      docker_compose:
        project_name: main-postgres
        definition:
          version: '3.7'
          services:
            p:
              image: "{{ postgres_version }}"
              container_name: postgresql
              restart: always
              volumes:
                - "{{ postgres_dir }}/data:/var/lib/postgresql/data"
                - "{{ postgres_dir }}/postgres_init_scripts:/docker-entrypoint-initdb.d"
              environment:
                POSTGRES_PASSWORD: {{ postgres_pass }}
                POSTGRES_USER: {{ postgres_user }}
              ports:
                - "{{ postgres_ip }}:{{ postgres_port }}:5432"
              logging:
                driver: "loki"
                options:
                  loki-url: "{{ loki_url }}"
                  loki-batch-size: "{{ loki_batch_size }}"
                  loki-retries: "{{ loki_retries }}"
...

kei hea loki_url: kube-loki.example.domain/loki/api/v1/push

Inenga

Ka kohia nga inenga mai i te PostgreSQL ma te whakamahi postgres_exporter ki Prometheus. Te haere tonu o te konae i runga ake nei Ka taea pukapuka takaro.

postgres.yaml

...
            pexp:
              image: "wrouesnel/postgres_exporter"
              container_name: pexporter
              restart: unless-stopped
              environment:
                DATA_SOURCE_NAME: "postgresql://{{ postgres_user }}:{{ postgres_pass }}@p:5432/postgres?sslmode=disable"
              ports:
                - "{{ postgres_ip }}:{{ postgres_exporter_port }}:9187"
              logging:
                driver: "json-file"
                options:
                  max-size: "5m"
...

Mo te whakamarama ake, ka tuhia e matou nga ingoa o nga ratonga tuuturu o waho ma te whakamahi i nga Tohu Whakamutunga.

postgres-service.yaml

apiVersion: v1
kind: Endpoints
metadata:
  name: postgres-exporter
subsets:
  - addresses:
      - ip: {{ .Values.service.postgres.ip }}
    ports:
      - port: {{ .Values.service.postgres.port }}
        protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: postgres-exporter
  labels:
    chart:  "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  ports:
    - protocol: TCP
      port: {{ .Values.service.postgres.port }}
      targetPort: {{ .Values.service.postgres.port }}

Ko te whirihora i a Prometheus kia whiwhi raraunga postgres_exporter ka mahia ma te whakatika i nga uara kei roto i te tutohi iti.

uara.yaml

scrape_configs:
...
  - job_name: postgres-exporter
    static_configs:
      - targets: 
         - postgres-exporter.applicationnamespace.svc.cluster.local:9187
        labels:
          alias: postgres
...

Hei tiro i nga raraunga kua riro, whakauruhia te Papatohu tika ki roto
Karepe me te whirihora i nga puna raraunga. Ka taea hoki tenei na roto i nga uara i roto i te mahere iti o Grafana.

He aha te ahua
Te aro turuki me te taki i nga ratonga o waho ki te roopu Kubernetes

Ko taku tumanako i awhina tenei tuhinga poto ki a koe ki te mohio ki nga whakaaro matua kei muri i tenei otinga me te whakaora i a koe i te wa e whakarite ana i te tirotiro me te takiuru o nga ratonga o waho mo Loki/Prometheus i roto i te roopu Kubernetes.

Source: will.com

Tāpiri i te kōrero