Chapter XIII Analysis takes you through helm3 Prometheus with ease

Keywords: Linux Kubernetes GitLab Nginx nexus

This series of articles:


Chapter 1: Nine analysis takes you through helm3 installation easily
Chapter II: Nine analyses take you through the helm3 public warehouse easily

Chapter III: Nine analyses take you through the helm3 private warehouse easily

Chapter IV: Nine analysis takes you through helm3 chart easily

Chapter V: Nine analysis takes you through helm3 release easily

Chapter VI: Nine analysis takes you through helm3 gitlab easily

Chapter VII: Nine analysis takes you through helm3 nginx-ingress easily

Chapter VIII: Nine analysis takes you through helm3 gitlab nfs easily

Chapter IX: Nine analysis takes you through helm3 nexus easily

Chapter 10: Nine analysis takes you through helm3 heapster easily

Chapter 11: Nine analysis takes you through helm3 kubernetes-dashboard easily

Chapter 12: Nine analysis takes you through helm3 harbor easily

Chapter 13: Nine analysis takes you through helm3 prometheus easily

Catalog

1 Preface

2 Download Prometheus

3 Create prometheus namespace

4 Install prometheus

4.1 Modify deployment apiVersion

4.2 Add daemonset selector

4.3 Add deployment selector

4.4 Modify ingress apiVersion

4.5 Verify prometheus installation

5 Install nfs

6 Create pv

7 Verify prometheus

8 Modify service type

9 Visit prometheus

1 Preface

This paper uses helm v3.0.0; k8s v1.16.3.

2 Download Prometheus

helm Search Prometheus:

helm  search repo prometheus

helm Download Unzip Prometheus:

helm fetch stable/prometheus

tar -zxvf prometheus-5.4.0.tgz

3 Create prometheus namespace

kubectl create ns prometheus

4 Install prometheus

The first prometheus is the helm release name, the second is the namespace, and the third is the prometheus local decompression directory.

helm install prometheus -n prometheus prometheus

4.1 Modify deployment apiVersion

If there are any errors during installation:

Error: unable to build kubernetes objects from release manifest: unable to recognize "": no matches for kind "Deployment" in version "extensions/v1beta1"

Implement the following statements to complete the explosion easily:

grep -irl 'extensions/v1beta1' prometheus/ | xargs sed -i 's#extensions/v1beta1#apps/v1#g'

4.2 Add daemonset selector

If the following error occurs in re-installation:

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(DaemonSet.spec): missing required field "selector" in io.k8s.api.apps.v1.DaemonSetSpec

Edit the templates/node-exporter-daemonset.yaml file and add the following:

4.3 Add deployment selector:

Install again if the following error occurs:

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec

Edit the templates/alertmanager-deployment.yaml file and add the following:

Edit the templates/kube-state-metrics-deployment.yaml file and add the following:

Edit the templates/pushgateway-deployment.yaml file and add the following:

Edit the templates/server-deployment.yaml file and add the following:

4.4 Modify ingress apiVersion

Install again if the following error occurs:

Error: unable to build kubernetes objects from release manifest: unable to recognize "": no matches for kind "Ingress" in version "apps/v1"

Edit the templates/alertmanager-ingress.yaml file and modify apps/v1 to extensions/v1beta1:

4.5 Verify prometheus installation

If you perform the installation, display the following:

Implement the following action statement and if the following results occur, the installation is successful:

helm list -n prometheus

However, successful installation does not mean successful operation.Further configuration is required.

5 Install nfs

How to install an nfs server, please refer to my " Easy explosion of nfs installation "Don't worry, it's easy to explode, so you can easily explode in minutes.

mkdir -p /data/nfs/prometheus/2g

mkdir -p /data/nfs/prometheus/8g

chmod 777 -R /data/nfs/prometheus

systemctl restart nfs

6 Create pv

After installing nfs, check prometheus pvc:

kubectl get pvc -n prometheus

The pvc was found to be in pending state because there are no available PVS to use and a pv needs to be created manually.

2 application specifications for pvc were found, 2 Gi and 8 Gi, respectively.The pv resource files are created separately below. Note that the server address here is the address of the nfs server.

Create the pv-prometheus-2g.yaml file as follows:

apiVersion: v1

kind: PersistentVolume

metadata:

    name: prometheus-2g

spec:

    capacity:

        storage: 2Gi

    volumeMode: Filesystem

    accessModes:

    -  ReadWriteOnce

    persistentVolumeReclaimPolicy: Retain

    nfs:

        server: 10.110.101.106

        path: /data/nfs/prometheus/2g

Create the pv-prometheus-8g.yaml file as follows:

apiVersion: v1

kind: PersistentVolume

metadata:

    name: prometheus-8g

spec:

    capacity:

        storage: 8Gi

    volumeMode: Filesystem

    accessModes:

    -  ReadWriteOnce

    persistentVolumeReclaimPolicy: Retain

    nfs:

        server: 10.110.101.106

        path: /data/nfs/prometheus/8g

Create a pv by executing the following statement:

kubectl apply -f pv-prometheus-2g.yaml

kubectl apply -f pv-prometheus-8g.yaml

View pvc status:

kubectl get pvc -n prometheus

* Since then, pvc and pv have been associated.

7 Verify prometheus

* Looking at the status of the prometheus pod, we found that the prometheus-server was not started successfully:

kubectl get pod -n prometheus

Review the status of the container log and find the following errors:

err="Error loading config couldn't load configuration (--config.file=/etc/config/prometheus.yml): parsing YAML file /etc/config/prometheus.yml: yaml: line 160: mapping values are not allowed in this context"

Solutions:

kubectl edit configmap -n prometheus prometheus-prometheus-server

Locate "target_label: kubernetes_pod_namealerting:"

Modify to:

Finish modifying, save, exit, then delete the prometheus-prometheus-server pod and let the controller regenerate the new pod to read the modified configmap information.Looking at the entire pod status again, we found that all started successfully:

8 Modify service type

Modify prometheus service type to NodePort type:

kubectl patch svc -n prometheus prometheus-prometheus-server -p '{"spec": {"type": "NodePort"}}'

kubectl get svc -n prometheus

9 Visit prometheus

Open your browser and visit prometheus-server. Note that the port is correct. I am 30347:

The helm3 installation of prometheus has since exploded easily.

Posted by webdogjcn on Thu, 09 Jan 2020 11:12:51 -0800