Editing CKA: Create and configure basic Pods
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | == Create a Pod == | |
− | |||
− | == Create a | ||
* To create a pod based on a yaml definition file: <code>[[kubectl apply]] -f https://k8s.io/examples/pods/storage/redis.yaml</code><ref>https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/</ref> | * To create a pod based on a yaml definition file: <code>[[kubectl apply]] -f https://k8s.io/examples/pods/storage/redis.yaml</code><ref>https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/</ref> | ||
* To create a pod in a [[namespace]]: | * To create a pod in a [[namespace]]: | ||
:<code>[[kubectl create]] namespace MY_TEST_NAMESPACE</code> | :<code>[[kubectl create]] namespace MY_TEST_NAMESPACE</code> | ||
− | :<code>[[kubectl | + | :<code>[[devOps/Kubernetes/kubectl|kubectl]] apply -f https://k8s.io/examples/pods/storage/redis.yaml --namespace=MY_TEST_NAMESPACE</code><ref>https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/</ref> |
:To verify container is running: | :To verify container is running: | ||
− | ::<code>[[kubectl get | + | ::<code>[[kubectl get]] pod NAME_POD --namespace=MY_TEST_NAMESPACE</code> |
+ | DevOps/Kubernetes/Certified Kubernetes Administrator/Create and configure basic Pods|Create and configure basic Pods]] | ||
+ | |||
+ | ==Set up a [[DevOps/Kubernetes/Volumes|Volume]] for a [[DevOps/Kubernetes/Pods|Pod]]== | ||
+ | The file system of a [[DevOps/Container|Container]] exists as long as the Container exists. Therefore, when a Container is destroyed or restarted, changes made to the file system are lost. For more consistent storage that is independent of the Container life cycle, you can use a Volume, review different Volume types in https://kubernetes.io/docs/concepts/storage/volumes/#types-of-volumes. | ||
+ | |||
+ | This feature is especially important for applications that must maintain a status, such as key-value storage engines (for example Redis) and databases. | ||
− | + | Create a Pod that runs a single Container. This Pod has a Volume of type <code>emptyDir</code> (empty directory) (see [[DevOps/Kubernetes/Volumes|Volume]] for volume types) that exists throughout the Pod's life cycle, even when the Container is destroyed and restarted. Here is the Pod configuration file: | |
− | |||
− | |||
− | |||
<code>pods/storage/redis.yaml</code> | <code>pods/storage/redis.yaml</code> | ||
− | + | <pre>apiVersion: v1 | |
− | + | kind: Pod | |
− | + | metadata: | |
− | + | name: redis | |
− | + | spec: | |
− | + | containers: | |
− | + | - name: redis | |
− | + | image: redis | |
− | + | volumeMounts: | |
− | + | - name: redis-storage | |
− | + | mountPath: /data/redis | |
− | + | volumes: | |
− | + | - name: redis-storage | |
− | + | emptyDir: {}</pre> | |
+ | |||
− | + | '''1.Create the Pod''' | |
− | + | <code>kubectl apply -f https://k8s.io/examples/pods/storage/redis.yaml</code> | |
− | |||
− | |||
− | + | '''2. Verify the Pod Container is running''' | |
+ | <code>kubectl get pod redis --watch</code> | ||
− | + | output: | |
− | |||
− | |||
− | + | <pre>NAME READY STATUS RESTARTS AGE | |
− | + | redis 1/1 Running 0 13s</pre> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | '''3.In another terminal, open an interactive session inside the Container that is running:''' | |
− | <code> | + | <code>kubectl exec -it redis -- /bin/bash</code> |
− | ''' | + | '''4.In the terminal, go to <code>/data/redis</code> and create a file:''' |
<pre>root@redis:/data# cd /data/redis/ | <pre>root@redis:/data# cd /data/redis/ | ||
root@redis:/data/redis# echo Hello > test-file</pre> | root@redis:/data/redis# echo Hello > test-file</pre> | ||
− | ''' | + | '''5.In the terminal, list the running processes:''' |
<pre>root@redis:/data/redis# apt-get update | <pre>root@redis:/data/redis# apt-get update | ||
root@redis:/data/redis# apt-get install procps | root@redis:/data/redis# apt-get install procps | ||
Line 68: | Line 62: | ||
root 15 0.0 0.0 17500 2072 ? R+ 00:48 0:00 ps aux</pre> | root 15 0.0 0.0 17500 2072 ? R+ 00:48 0:00 ps aux</pre> | ||
− | + | 6.In the terminal, kill the Redis process: | |
root@redis:/data/redis# kill <pid> | root@redis:/data/redis# kill <pid> | ||
Line 74: | Line 68: | ||
where <pid>is the process ID (PID) of Redis. | where <pid>is the process ID (PID) of Redis. | ||
− | + | 7.In the original terminal, observe the changes in the Redis Pod. You will eventually see something like the following: | |
NAME READY STATUS RESTARTS AGE | NAME READY STATUS RESTARTS AGE | ||
Line 84: | Line 78: | ||
1.Open a terminal in the restarted Container: | 1.Open a terminal in the restarted Container: | ||
− | + | ||
+ | [[kubectl exec]] -it redis -- /bin/bash | ||
2.In the terminal, go to /data/redisand verify that it test-filestill exists: | 2.In the terminal, go to /data/redisand verify that it test-filestill exists: | ||
Line 93: | Line 88: | ||
3.Remove the Pod you created for this exercise: | 3.Remove the Pod you created for this exercise: | ||
− | |||
− | + | kubectl delete pod redis | |
− | |||
== See also == | == See also == | ||
− | * | + | * [[Certified Kubernetes Administrator]] |
− | |||
− | |||
{{CC license}} | {{CC license}} | ||
Source: https://en.wikiversity.org/wiki/DevOps/Kubernetes/Certified_Kubernetes_Administrator/Create_and_configure_basic_Pods | Source: https://en.wikiversity.org/wiki/DevOps/Kubernetes/Certified_Kubernetes_Administrator/Create_and_configure_basic_Pods | ||
− | |||
− | |||
− | |||
− |
Advertising: