背景概要みなさんこんにちは。An Ruoです。数日前、グループ内の友人から、Kubernetes イベントを収集、監視、アラームする方法を尋ねられました。そこで、この機会に現在の解決策を共有したいと思います。 完成品展示今回はイベント表示のみを共有し、アラームは含めませんでした。次回機会があればまたシェアしたいと思います。 写真 画像 写真 画像 写真 ここでのワードクラウドはプラグインをインストールする必要があるため表示されません。自分でインストールして設定することができます。 実際の例環境説明写真 エクスポーターの展開[root@192 deploy]# cat 00-roles.yaml apiVersion: v1 kind: Namespace metadata: name: kube-ops --- apiVersion: v1 kind: ServiceAccount metadata: namespace: kube-ops name: event-exporter --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: event-exporter roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: view subjects: - kind: ServiceAccount namespace: kube-ops name: event-exporter
[root@192 deploy]# cat 02-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: event-exporter namespace: kube-ops spec: replicas: 1 template: metadata: labels: app: event-exporter version: v1 spec: serviceAccountName: event-exporter containers: - name: event-exporter image: m.daocloud.io/ghcr.io/opsgenie/kubernetes-event-exporter:v0.11 imagePullPolicy: IfNotPresent args: - -cnotallow=/data/config.yaml volumeMounts: - mountPath: /data name: cfg volumes: - name: cfg configMap: name: event-exporter-cfg selector: matchLabels: app: event-exporter version: v1 上記の yaml ファイルを実行し、ここではスキップします。自分で百度を検索することはしません。 Elasticsearch のデプロイメント- elasticsearch 圧縮パッケージをダウンロード
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.4-linux-x86_64.tar.gz
### 创建存放包的文件夹# mkdir /data/soft -p # tar -xvf elasticsearch-8.10.4-linux-x86_64.tar.gz -C /data/soft/
- 設定ファイルconfig/elasticsearch.ymlを変更します。
cluster.name: my-elk node.name: node-1 path.data: /data/soft/elasticsearch-8.10.4/data path.logs: /data/soft/elasticsearch-8.10.4/logs network.host: 0.0.0.0 http.port: 9200 # cat >> /etc/security/limits.conf <<EOF es hard nofile 65535 es soft nofile 65535 es nproc 4096 es hard memlock unlimited es soft memlock unlimited EOF # cat >> /etc/sysctl.conf <<EOF vm.swappiness=1 vm.max_map_count=262144 EOF ### 使其生效# sysctl --system # su - root
# useradd es
# chown es:es elasticsearch-8.10.4/ -R
# /etc/systemd/system/elasticsearch.service [Unit] Descriptinotallow=Elasticsearch Documentatinotallow=https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html [Service] User=es ExecStart=/data/soft/elasticsearch-8.10.4/bin/elasticsearch TimeoutStopSec=20 Restart=always LimitNOFILE=65536 [Install] WantedBy=multi-user.target
リロードして起動する方法については、ここでは省略します。自分で百度を検索することはしません。 elasticsearch パスワードをリセット # ./elasticsearch-reset-password -u elastic This tool will reset the password of the [elastic] user to an autogenerated value. The password will be printed in the console. Please confirm that you would like to continue [y/N]y Password for the [elastic] user successfully reset. New value: l5tL-0v74o15RlMzVkY elastic ユーザーのパスワードをリセットするときは、「OK」と入力して新しいパスワードを生成します。ここでのパスワードは: l5tL-0v74o15RlMzVkY
Grafana のデプロイメントwget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.2.linux-amd64.tar.gz
tar -xvf grafana-enterprise-9.4.2.linux-amd64.tar.gz -C /data/soft
nohup ./grafana-server >/dev/null 2>&1 & ここで直接起動するには nohup を使用します。もちろん、kubernetes、docker などにデプロイすることもできます。
GrafanaはElasticに接続します写真 ここでの ca は elastc にあり、特定のパスは config/certs/http_ca.crt です。ここでのパスワードはリセットした es パスワードです。 写真 写真 ここではあまり詳しく説明しません。わからないことがあれば、グループに参加して質問してください。 ダッシュボードをインポート写真 要約するこの時点で、イベントに関するプレゼンテーションは基本的に完了しています。アラームの共有については、時間が許せば再度共有します。 |