...

/

Using hostPath Volume Type to Inject Configuration Files

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:

Press + to interact
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: prometheus
annotations:
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /prometheus
pathType: ImplementationSpecific
backend:
service:
name: prometheus
port:
number: 9090
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
spec:
selector:
matchLabels:
type: monitor
service: prometheus
strategy:
type: Recreate
template:
metadata:
labels:
type: monitor
service: prometheus
spec:
containers:
- name: prometheus
image: prom/prometheus:v2.0.0
command:
- /bin/prometheus
args:
- "--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: v1
kind: Service
metadata:
name: prometheus
spec:
ports:
- port: 9090
selector:
type: monitor
service: 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.

Press + to interact
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: prometheus
annotations:
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /prometheus
pathType: ImplementationSpecific
backend:
service:
name: prometheus
port:
number: 9090
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
spec:
selector:
matchLabels:
type: monitor
service: prometheus
strategy:
type: Recreate
template:
metadata:
labels:
type: monitor
service: prometheus
spec:
containers:
- name: prometheus
image: prom/prometheus:v2.0.0
command:
- /bin/prometheus
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share"
- "--web.external-url={{EDUCATIVE_LIVE_VM_URL}}/prometheus"
---
apiVersion: v1
kind: Service
metadata:
name: prometheus
spec:
ports:
- port: 9090
selector:
type: monitor
service: prometheus

Now that the URL is updated, let's create deployments:

Press + to interact
kubectl create -f prometheus.yml
kubectl 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 ...