bureaucraten, interfacemoderatoren, Beheerders (Semantic MediaWiki), Curatoren (Semantic MediaWiki), Redacteuren (Semantic MediaWiki), toezichthouders, beheerders
205
bewerkingen
Regel 205: | Regel 205: | ||
So let's try adding a Volume to our pod, to see if we can make some changes persistent. Kubernetes supports [https://kubernetes.io/docs/concepts/storage/volumes/#types-of-volumes many types of volumes]; in this case we use <code>[https://kubernetes.io/docs/concepts/storage/volumes/#emptydir emptyDir]</code> which is just a locally stored disk (initially empty). | So let's try adding a Volume to our pod, to see if we can make some changes persistent. Kubernetes supports [https://kubernetes.io/docs/concepts/storage/volumes/#types-of-volumes many types of volumes]; in this case we use <code>[https://kubernetes.io/docs/concepts/storage/volumes/#emptydir emptyDir]</code> which is just a locally stored disk (initially empty). | ||
There is no command-line parameter to <code>kubectl run</code> to add volumes. Internally, <code>kubectl run</code> translates your commandline to a JSON request to the Kubernetes API server; we'd have to add any additional requests directly into the JSON. This can be done with the <code>--overrides</code> flag, but at this point, it is probably easier to switch to sending those commands ourselves. We can use JSON for this too, but many users use YAML for this, so we will too. | |||
The command above, <code>kubectl run --restart=Never -ti --image=ubuntu:bionic bash</code>, translates to the following YAML: | |||
<pre> | |||
apiVersion: v1 | |||
kind: Pod | |||
metadata: | |||
name: bash | |||
spec: | |||
containers: | |||
- name: bash | |||
image: ubuntu:bionic | |||
stdin: true | |||
stdinOnce: true | |||
tty: true | |||
</pre> | |||
As you can see, this is a Pod named "bash" and with one container, also called "bash", running <code>ubuntu:bionic</code>. | |||
To create this Pod and attach to it, we write the code above to <code>bash.yaml</code> and run these commands: | |||
<pre> | |||
$ 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:/# exit 0 | |||
exit | |||
$ kubectl delete pod bash | |||
</pre> | |||
Now, we will recreate the pod with an <code>emptyDir</code> volume mounted at <code>/foo</code>. | |||
<pre> | |||
$ cat bash.yaml | |||
apiVersion: v1 | |||
kind: Pod | |||
metadata: | |||
name: bash | |||
spec: | |||
volumes: | |||
- name: testing-volume | |||
emptyDir: {} | |||
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:/# mount | grep foo | |||
/dev/mapper/ubuntu--vg-root on /foo type ext4 (rw,relatime,errors=remount-ro,data=ordered) | |||
root@bash:/# exit 0 | |||
exit | |||
$ kubectl delete pod bash | |||
</pre> | |||
Of course, this volume isn't persistent just yet; restarts of the pod will cause it to be recreated so it actually doesn't serve our purpose just yet. | |||
= Creating your own pods = | = Creating your own pods = |