Skip to main content

ReStructuredText Demo

k8s-volumes

#NFS Volumes create NFS share on my QNAP with squash option no_root_squash.

#Local volumes Didnt manage to launch

Change nodes ip sudo vim /var/lib/kubelet/kubeadm-flags.env --node-ip=192.168.50.12 KUBELET_KUBEADM_ARGS="--cgroup-driver=cgroupfs --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.2 --resolv-conf=/run/systemd/resolve/resolv.conf --node-ip=192.168.50.12"

systemctl restart kubelet

#exec

kubectl exec --stdin --tty mysql-deployment-bfcd64b55-mqp4q -- /bin/bash

#sharing vol between pods My working solutuion not advised:

apiVersion: v1 kind: PersistentVolume metadata:

System Message: ERROR/3 (<string>, line 28)

Unexpected indentation.

name: task-pv-volume labels:

System Message: ERROR/3 (<string>, line 30)

Unexpected indentation.

type: local

System Message: WARNING/2 (<string>, line 31)

Block quote ends without a blank line; unexpected unindent.

spec:

storageClassName: manual capacity:

System Message: ERROR/3 (<string>, line 34)

Unexpected indentation.

storage: 1Gi

System Message: WARNING/2 (<string>, line 35)

Block quote ends without a blank line; unexpected unindent.

accessModes:
  • ReadWriteOnce

hostPath:

path: "/mnt/data"

System Message: WARNING/2 (<string>, line 39)

Definition list ends without a blank line; unexpected unindent.

apiVersion: v1 kind: PersistentVolumeClaim metadata:

System Message: ERROR/3 (<string>, line 42)

Unexpected indentation.

name: task-pv-claim

System Message: WARNING/2 (<string>, line 43)

Block quote ends without a blank line; unexpected unindent.

spec:

storageClassName: manual accessModes:

System Message: ERROR/3 (<string>, line 46)

Unexpected indentation.

  • ReadWriteOnce

System Message: WARNING/2 (<string>, line 47)

Block quote ends without a blank line; unexpected unindent.

resources:
requests:

storage: 1Gi

apiVersion: apps/v1 kind: Deployment metadata:

System Message: ERROR/3 (<string>, line 54)

Unexpected indentation.

name: mysql-deployment labels:

System Message: ERROR/3 (<string>, line 56)

Unexpected indentation.

app: mysql

System Message: WARNING/2 (<string>, line 57)

Block quote ends without a blank line; unexpected unindent.

spec:

replicas: 1 selector:

System Message: ERROR/3 (<string>, line 60)

Unexpected indentation.

matchLabels:

app: mysql

System Message: WARNING/2 (<string>, line 62)

Block quote ends without a blank line; unexpected unindent.

template:
metadata:
labels:

app: mysql

spec:
containers:
  • name: mysql image: mysql:5.7 ports:

    System Message: ERROR/3 (<string>, line 71)

    Unexpected indentation.

    • containerPort: 3306

    System Message: WARNING/2 (<string>, line 72)

    Block quote ends without a blank line; unexpected unindent.

    volumeMounts:
    • mountPath: "/var/lib/mysql" subPath: "mysql" name: mysql-data

    env:
    • name: MYSQL_ROOT_PASSWORD valueFrom:

      System Message: ERROR/3 (<string>, line 79)

      Unexpected indentation.

      secretKeyRef:

      name: mysql-secrets key: ROOT_PASSWORD

volumes:
  • name: mysql-data persistentVolumeClaim:

    System Message: ERROR/3 (<string>, line 85)

    Unexpected indentation.

    claimName: task-pv-claim

#sharing dir between pods

First of all. Kubernetes doesn't have integrated functionality to share storage between hosts. There are several options below. But first how to share storage if you already have some volumes set up.

To share a volume between multiple pods you'd need to create a PVC with access mode ReadWriteMany

kind: PersistentVolumeClaim apiVersion: v1 metadata:

System Message: ERROR/3 (<string>, line 99)

Unexpected indentation.

name: my-pvc

System Message: WARNING/2 (<string>, line 100)

Block quote ends without a blank line; unexpected unindent.

spec:
accessModes:
  • ReadWriteMany

System Message: WARNING/2 (<string>, line 103)

Definition list ends without a blank line; unexpected unindent.

storageClassName: myvolume resources:

System Message: ERROR/3 (<string>, line 105)

Unexpected indentation.

requests:

storage: 1Gi

System Message: WARNING/2 (<string>, line 107)

Definition list ends without a blank line; unexpected unindent.

After that you can mount it to multiple pods:

apiVersion: v1 kind: Pod metadata:

System Message: ERROR/3 (<string>, line 112)

Unexpected indentation.

name: myapp1

System Message: WARNING/2 (<string>, line 113)

Block quote ends without a blank line; unexpected unindent.

spec:

containers:

System Message: WARNING/2 (<string>, line 115)

Definition list ends without a blank line; unexpected unindent.

...
volumeMounts:
  • mountPath: /data name: data subPath: app1

System Message: WARNING/2 (<string>, line 120)

Block quote ends without a blank line; unexpected unindent.

volumes:
  • name: data persistentVolumeClaim:

    System Message: ERROR/3 (<string>, line 123)

    Unexpected indentation.

    claimName: 'my-pvc'

System Message: WARNING/2 (<string>, line 124)

Definition list ends without a blank line; unexpected unindent.

--- apiVersion: v1 kind: Pod metadata:

System Message: ERROR/3 (<string>, line 128)

Unexpected indentation.

name: myapp2

System Message: WARNING/2 (<string>, line 129)

Block quote ends without a blank line; unexpected unindent.

spec:

containers:

System Message: WARNING/2 (<string>, line 131)

Definition list ends without a blank line; unexpected unindent.

...
volumeMounts:
  • mountPath: /data name: data subPath: app2

System Message: WARNING/2 (<string>, line 136)

Block quote ends without a blank line; unexpected unindent.

volumes:
  • name: data persistentVolumeClaim:

    System Message: ERROR/3 (<string>, line 139)

    Unexpected indentation.

    claimName: 'my-pvc'

System Message: WARNING/2 (<string>, line 140)

Definition list ends without a blank line; unexpected unindent.

Of course, persistent volume must be accessible via network. Otherwise you'd need to make sure that all the pods are scheduled to the node with that volume.

There are several volume types that are suitable for that and not tied to any cloud provider:

NFS RBD (Ceph Block Device) CephFS Glusterfs Portworx Volumes Of course, to use a volume you need to have it first. That is, if you want to consume NFS you need to setup NFS on all nodes in K8s cluster. If you want to consume Ceph, you need to setup Ceph cluster and so on.

The only volume type that supports Kubernetes out of the box is Portworks. There are instruction on how to set it up in GKE.

To setup Ceph cluster in K8s there's a project in development called Rook.

But this is all overkill if you just want a folder from one node to be available in another node. In this case just setup NFS server. It wouldn't be harder than provisioning other volume types and will consume much less cpu/memory/disk resources. ## Example1 Configure a Pod to Use a PersistentVolume for Storage

https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/

apiVersion: v1 kind: PersistentVolume metadata:

System Message: ERROR/3 (<string>, line 163)

Unexpected indentation.

name: mysql-pv-volume labels:

System Message: ERROR/3 (<string>, line 165)

Unexpected indentation.

type: local

System Message: WARNING/2 (<string>, line 166)

Block quote ends without a blank line; unexpected unindent.

spec:
capacity:

storage: 1Gi

accessModes:
  • ReadWriteOnce

System Message: WARNING/2 (<string>, line 171)

Definition list ends without a blank line; unexpected unindent.

persistentVolumeReclaimPolicy: Retain storageClassName: local-storage local:

System Message: ERROR/3 (<string>, line 174)

Unexpected indentation.

path: /mnt/data

System Message: WARNING/2 (<string>, line 175)

Block quote ends without a blank line; unexpected unindent.

nodeAffinity:
required:

nodeSelectorTerms: - matchExpressions:

System Message: ERROR/3 (<string>, line 179)

Unexpected indentation.

  • key: kubernetes.io/hostname operator: In values: - node

apiVersion: v1 kind: PersistentVolumeClaim metadata:

System Message: ERROR/3 (<string>, line 187)

Unexpected indentation.

name: mysql-pv-claim

System Message: WARNING/2 (<string>, line 188)

Block quote ends without a blank line; unexpected unindent.

spec:

storageClassName: local-storage accessModes:

System Message: ERROR/3 (<string>, line 191)

Unexpected indentation.

  • ReadWriteOnce

System Message: WARNING/2 (<string>, line 192)

Block quote ends without a blank line; unexpected unindent.

resources:
requests:

storage: 1Gi

Comments

Comments powered by Disqus