Deploy Grafana on Kubernetes Cluster

Task :

The Nautilus DevOps teams is planning to set up a Grafana tool to collect and analyze analytics from some applications. They are planning to deploy it on Kubernetes cluster. Below you can find more details.

1.) Create a namespace for Grafana grafana-monitoring-xfusion.

2.) Create grafana-deployment-xfusion deployment the namespace you created.

a. Replica counts should be 1.

b. Container name should be grafana-container-xfusion and use grafana/grafana:latest image.

c. Container port should be 3000. Set resources limits memory to 2Gi and CPU to 1000m, requests for memory 1Gi and for CPU 500m.

d. Volume mount name should be grafana-storage. Its mountPath should be /var/lib/grafana. Volume name should be grafana-storage, should be emptyDir {}.

3.) Create grafana-service-xfusion service under the same namespace. It must be of NodePort type, its port must be 3000, target port must be 3000 and nodePort must be 32000.

You can use any labels as per your choice.

Note: The kubeclt on jump_host has been configured to work with kubernetes cluster.

Solution :

$ kubectl create namespace grafana-monitoring-xfusion
$ sudo vi grafana-deployment-xfusion.yaml
apiVersion: v1
kind: Service
metadata:
  name: grafana-service-xfusion
  namespace: grafana-monitoring-xfusion
spec:
  type: NodePort
  selector:
    app: grafana
  ports:
    - port: 3000
      targetPort: 3000
      nodePort: 32000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-deployment-xfusion
  namespace: grafana-monitoring-xfusion
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      volumes:
      - name: grafana-storage
        emptyDir: {}
      containers:
      - name: grafana-container-xfusion
        image: grafana/grafana:latest
        volumeMounts:
        - name: grafana-storage
          mountPath: /var/lib/grafana
        resources:
          requests:
            memory: "1Gi"
            cpu: "500m"
          limits:
            memory: "2Gi"
            cpu: "1000m"
          ports:
          - containerPort: 3000
$ kubectl apply -f grafana-deployment-xfusion.yaml 
$ kubectl get deployment --namespace grafana-monitoring-xfusion
$ kubectl get service --namespace grafana-monitoring-xfusion

Leave a Reply

Your email address will not be published. Required fields are marked *