Simple explanation of docker volume in Kubernetes

7/17/2020

I am transitioning from docker to Kubernetes. Had been volumes on docker to expose files needed by container, just like the example below to provide grafana container some files.

I am confused on how the same can be established in Kubernetes using volumeMounts and volumes, and how is it linked to PersistentVolumeClaim.

version: '3'

volumes:
  grafana_app_data: {}

services:
  grafana:
    image: grafana/grafana:latest
    volumes:
      - grafana_app_data:/var/lib/grafana
      - ./directory-on-local-machine/:/etc/grafana/provisioning/
-- maopuppets
kubernetes

1 Answer

7/17/2020

A Pod Spec that is equivalent ↔️ would be something like this:

apiVersion: v1
kind: Pod
metadata:
  name: grafana-pod
spec:
  containers:
  - image: grafana/grafana:latest
    name: grafana-container
    volumeMounts:
    - mountPath: /var/lib/grafana
      name: grafana-app-data
    - mountPath: /etc/grafana/provisioning
      name: grafana-provisioning
  volumes:
  - name: grafana-app-data
    hostPath:
      path: /grafana-data
      type: Directory
  - name: grafana-provisioning
    hostPath:
      path: /directory-on-machiche
      type: Directory

This is using basic hostPath, you can also use a local volume πŸ’Ύ or any other type of supported volume depending on what you need. πŸ’ΎπŸ“€πŸ’ΏπŸ’½

-- Rico
Source: StackOverflow