DEV Community

Cover image for 7.Deploy Grafana on Kubernetes Cluster
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

7.Deploy Grafana on Kubernetes Cluster

Lab Information

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 deployment named grafana-deployment-devops using any grafana image for Grafana app. Set other parameters as per your choice.

2.) Create NodePort type service with nodePort 32000 to expose the app.

You need not to make any configuration changes inside the Grafana app once deployed, just make sure you are able to access the Grafana login page.

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

Lab Solutions

Step 1: Create the Grafana Deployment YAML file

First, create a deployment configuration file:

cat > grafana-deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-deployment-devops
  labels:
    app: grafana
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
      - name: grafana
        image: grafana/grafana:latest
        ports:
        - containerPort: 3000
        env:
        - name: GF_SECURITY_ADMIN_PASSWORD
          value: "admin123"
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
EOF
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the NodePort Service YAML file

Now create the service configuration:

cat > grafana-service.yaml << EOF
apiVersion: v1
kind: Service
metadata:
  name: grafana-service
  labels:
    app: grafana
spec:
  type: NodePort
  ports:
  - port: 3000
    targetPort: 3000
    nodePort: 32000
  selector:
    app: grafana
EOF
Enter fullscreen mode Exit fullscreen mode

Step 3: Deploy the Grafana Deployment

Apply the deployment to your Kubernetes cluster:

kubectl apply -f grafana-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Step 4: Deploy the NodePort Service

Apply the service configuration:

kubectl apply -f grafana-service.yaml
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify the Deployment

Check if the deployment was created successfully:

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

Step 6: Verify the Service

Check if the service is running:

kubectl get services
Enter fullscreen mode Exit fullscreen mode

Step 7: Check the Pod Status

Verify that the Grafana pod is running:

kubectl get pods -l app=grafana
Enter fullscreen mode Exit fullscreen mode

Step 8: Access Grafana


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)