bureaucraten, interfacemoderatoren, Beheerders (Semantic MediaWiki), Curatoren (Semantic MediaWiki), Redacteuren (Semantic MediaWiki), toezichthouders, beheerders
205
bewerkingen
Regel 272: | Regel 272: | ||
Of course, this volume isn't persistent just yet; restarts of the pod will cause it to be recreated (the Volume has the "lifetime of the Pod") so it actually doesn't serve our purpose. | Of course, this volume isn't persistent just yet; restarts of the pod will cause it to be recreated (the Volume has the "lifetime of the Pod") so it actually doesn't serve our purpose. | ||
For this, we need to create a PersistentVolume, that exists even outside our Pod, but is linked to it. ([https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/ Here's | For this, we need to create a PersistentVolume, that exists even outside our Pod, but is linked to it. Kubernetes supports [https://kubernetes.io/docs/concepts/storage/persistent-volumes/ a number of persistant volume types]. All of them use an external service for this, because all Nodes need to be able to access it (with the exception of "HostPath" persistent volumes, which only work on a single-node cluster. [https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/ Here's a tutorial for this if that's what you want].) | ||
The quickest way to set up persistent storage is to set up a NFS server: | |||
<pre> | |||
root@kubetest4:~# apt-get install -y nfs-kernel-server | |||
[...] | |||
root@kubetest4:~# mkdir /persistent | |||
root@kubetest4:~# cat <<EOF >>/etc/exports | |||
/persistent *(rw,sync,no_subtree_check) | |||
EOF | |||
root@kubetest4:~# exportfs -ra | |||
</pre> | |||
Make sure the other nodes can access it, by checking that <code>mkdir /persistent && mount -t nfs <ipaddress>:/persistent /persistent</code> works. | |||
Now, we can create a PersistentVolume for this NFS mount using the following YAML file: | |||
<pre> | |||
apiVersion: v1 | |||
kind: PersistentVolume | |||
metadata: | |||
name: mypersistentvolume | |||
spec: | |||
capacity: | |||
storage: 5Gi | |||
volumeMode: Filesystem | |||
accessModes: | |||
- ReadWriteMany | |||
persistentVolumeReclaimPolicy: Retain | |||
storageClassName: slow | |||
mountOptions: | |||
- hard | |||
- nfsvers=4.1 | |||
nfs: | |||
path: /persistent | |||
server: <ipaddress> | |||
</pre> | |||
And we'll need to make a PersistentVolumeClaim to claim the volume for our node: | |||
<pre> | |||
apiVersion: v1 | |||
kind: PersistentVolumeClaim | |||
metadata: | |||
name: myclaim | |||
spec: | |||
accessModes: | |||
- ReadWriteMany | |||
volumeMode: Filesystem | |||
resources: | |||
requests: | |||
storage: 5Gi | |||
storageClassName: slow | |||
selector: | |||
matchLabels: | |||
release: "stable" | |||
matchExpressions: | |||
- {key: environment, operator: In, values: [dev]} | |||
</pre> | |||
Now we can go ahead and create our pod with this volume: | |||
<pre> | |||
$ kubectl apply -f persistentvolume.yaml | |||
$ kubectl apply -f volumeclaim.yaml | |||
$ cat bash.yaml | |||
apiVersion: v1 | |||
kind: Pod | |||
metadata: | |||
name: bash | |||
spec: | |||
volumes: | |||
- name: testing-volume | |||
persistentVolumeClaim: | |||
claimName: myclaim | |||
containers: | |||
- name: bash | |||
image: ubuntu:bionic | |||
stdin: true | |||
stdinOnce: true | |||
tty: true | |||
volumeMounts: | |||
- mountPath: /foo | |||
name: testing-volume | |||
$ kubectl create -f bash.yaml | |||
pod/bash created | |||
$ kubectl attach -ti bash -c bash | |||
If you don't see a command prompt, try pressing enter. | |||
root@bash:/# | |||
</pre> | |||
= Creating your own pods = | = Creating your own pods = |