Using hostPath Volume Type to Inject Configuration Files
Explore Prometheus and configure it with hostPath volume.
Using Prometheus
We are about to deploy Prometheus for the first time. We won’t go into details about the application except that it’s best for your monitoring and alerting needs. We’ll use it only to demonstrate a few Kubernetes concepts. We won’t try to learn how to operate it here.
Looking into the definition
Let’s look at the application’s definition:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: prometheusannotations:kubernetes.io/ingress.class: "nginx"ingress.kubernetes.io/ssl-redirect: "false"nginx.ingress.kubernetes.io/ssl-redirect: "false"spec:rules:- http:paths:- path: /prometheuspathType: ImplementationSpecificbackend:service:name: prometheusport:number: 9090---apiVersion: apps/v1kind: Deploymentmetadata:name: prometheusspec:selector:matchLabels:type: monitorservice: prometheusstrategy:type: Recreatetemplate:metadata:labels:type: monitorservice: prometheusspec:containers:- name: prometheusimage: prom/prometheus:v2.0.0command:- /bin/prometheusargs:- "--config.file=/etc/prometheus/prometheus.yml"- "--storage.tsdb.path=/prometheus"- "--web.console.libraries=/usr/share"- "--web.external-url=http://192.168.99.100/prometheus"---apiVersion: v1kind: Servicemetadata:name: prometheusspec:ports:- port: 9090selector:type: monitorservice: prometheus
There’s nothing genuinely new in that YAML file. It defines an Ingress, a Deployment, and a Service. There is, however, one thing we might need to change.
Configuring the IP
Prometheus needs a full external URL if we want to change the base path. For practicing on our platform, the URL is set to Educative at line 49 in the following definition of `prometheus.yml.
apiVersion: networking.k8s.io/v1kind: Ingressmetadata:name: prometheusannotations:kubernetes.io/ingress.class: "nginx"ingress.kubernetes.io/ssl-redirect: "false"nginx.ingress.kubernetes.io/ssl-redirect: "false"spec:rules:- http:paths:- path: /prometheuspathType: ImplementationSpecificbackend:service:name: prometheusport:number: 9090---apiVersion: apps/v1kind: Deploymentmetadata:name: prometheusspec:selector:matchLabels:type: monitorservice: prometheusstrategy:type: Recreatetemplate:metadata:labels:type: monitorservice: prometheusspec:containers:- name: prometheusimage: prom/prometheus:v2.0.0command:- /bin/prometheusargs:- "--config.file=/etc/prometheus/prometheus.yml"- "--storage.tsdb.path=/prometheus"- "--web.console.libraries=/usr/share"- "--web.external-url={{EDUCATIVE_LIVE_VM_URL}}/prometheus"---apiVersion: v1kind: Servicemetadata:name: prometheusspec:ports:- port: 9090selector:type: monitorservice: prometheus
Now that the URL is updated, let's create deployments:
kubectl create -f prometheus.ymlkubectl rollout status deploy prometheus
Once we created the application, we used the kubectl rollout status
command to confirm that the deployment finished.
Testing Prometheus
Now, we can ...