cleanup page in configure-pod-container

This commit is contained in:
zhuzhenghao 2023-02-26 20:48:35 +08:00
parent f6d41d2959
commit bb4092c644
3 changed files with 77 additions and 77 deletions

View File

@ -12,27 +12,24 @@ for storage.
Here is a summary of the process: Here is a summary of the process:
1. You, as cluster administrator, create a PersistentVolume backed by physical 1. You, as cluster administrator, create a PersistentVolume backed by physical
storage. You do not associate the volume with any Pod. storage. You do not associate the volume with any Pod.
1. You, now taking the role of a developer / cluster user, create a 1. You, now taking the role of a developer / cluster user, create a
PersistentVolumeClaim that is automatically bound to a suitable PersistentVolumeClaim that is automatically bound to a suitable
PersistentVolume. PersistentVolume.
1. You create a Pod that uses the above PersistentVolumeClaim for storage. 1. You create a Pod that uses the above PersistentVolumeClaim for storage.
## {{% heading "prerequisites" %}} ## {{% heading "prerequisites" %}}
* You need to have a Kubernetes cluster that has only one Node, and the * You need to have a Kubernetes cluster that has only one Node, and the
{{< glossary_tooltip text="kubectl" term_id="kubectl" >}} {{< glossary_tooltip text="kubectl" term_id="kubectl" >}}
command-line tool must be configured to communicate with your cluster. If you command-line tool must be configured to communicate with your cluster. If you
do not already have a single-node cluster, you can create one by using do not already have a single-node cluster, you can create one by using
[Minikube](https://minikube.sigs.k8s.io/docs/). [Minikube](https://minikube.sigs.k8s.io/docs/).
* Familiarize yourself with the material in * Familiarize yourself with the material in
[Persistent Volumes](/docs/concepts/storage/persistent-volumes/). [Persistent Volumes](/docs/concepts/storage/persistent-volumes/).
<!-- steps --> <!-- steps -->
@ -50,7 +47,6 @@ In your shell on that Node, create a `/mnt/data` directory:
sudo mkdir /mnt/data sudo mkdir /mnt/data
``` ```
In the `/mnt/data` directory, create an `index.html` file: In the `/mnt/data` directory, create an `index.html` file:
```shell ```shell
@ -116,8 +112,10 @@ kubectl get pv task-pv-volume
The output shows that the PersistentVolume has a `STATUS` of `Available`. This The output shows that the PersistentVolume has a `STATUS` of `Available`. This
means it has not yet been bound to a PersistentVolumeClaim. means it has not yet been bound to a PersistentVolumeClaim.
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE ```
task-pv-volume 10Gi RWO Retain Available manual 4s NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
task-pv-volume 10Gi RWO Retain Available manual 4s
```
## Create a PersistentVolumeClaim ## Create a PersistentVolumeClaim
@ -132,7 +130,9 @@ Here is the configuration file for the PersistentVolumeClaim:
Create the PersistentVolumeClaim: Create the PersistentVolumeClaim:
kubectl apply -f https://k8s.io/examples/pods/storage/pv-claim.yaml ```shell
kubectl apply -f https://k8s.io/examples/pods/storage/pv-claim.yaml
```
After you create the PersistentVolumeClaim, the Kubernetes control plane looks After you create the PersistentVolumeClaim, the Kubernetes control plane looks
for a PersistentVolume that satisfies the claim's requirements. If the control for a PersistentVolume that satisfies the claim's requirements. If the control
@ -147,8 +147,10 @@ kubectl get pv task-pv-volume
Now the output shows a `STATUS` of `Bound`. Now the output shows a `STATUS` of `Bound`.
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE ```
task-pv-volume 10Gi RWO Retain Bound default/task-pv-claim manual 2m NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE
task-pv-volume 10Gi RWO Retain Bound default/task-pv-claim manual 2m
```
Look at the PersistentVolumeClaim: Look at the PersistentVolumeClaim:
@ -159,8 +161,10 @@ kubectl get pvc task-pv-claim
The output shows that the PersistentVolumeClaim is bound to your PersistentVolume, The output shows that the PersistentVolumeClaim is bound to your PersistentVolume,
`task-pv-volume`. `task-pv-volume`.
NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE ```
task-pv-claim Bound task-pv-volume 10Gi RWO manual 30s NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE
task-pv-claim Bound task-pv-volume 10Gi RWO manual 30s
```
## Create a Pod ## Create a Pod
@ -206,15 +210,16 @@ curl http://localhost/
The output shows the text that you wrote to the `index.html` file on the The output shows the text that you wrote to the `index.html` file on the
hostPath volume: hostPath volume:
Hello from Kubernetes storage ```
Hello from Kubernetes storage
```
If you see that message, you have successfully configured a Pod to If you see that message, you have successfully configured a Pod to
use storage from a PersistentVolumeClaim. use storage from a PersistentVolumeClaim.
## Clean up ## Clean up
Delete the Pod, the PersistentVolumeClaim and the PersistentVolume: Delete the Pod, the PersistentVolumeClaim and the PersistentVolume:
```shell ```shell
kubectl delete pod task-pv-pod kubectl delete pod task-pv-pod
@ -275,12 +280,8 @@ When a Pod consumes a PersistentVolume, the GIDs associated with the
PersistentVolume are not present on the Pod resource itself. PersistentVolume are not present on the Pod resource itself.
{{< /note >}} {{< /note >}}
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
* Learn more about [PersistentVolumes](/docs/concepts/storage/persistent-volumes/). * Learn more about [PersistentVolumes](/docs/concepts/storage/persistent-volumes/).
* Read the [Persistent Storage design document](https://git.k8s.io/design-proposals-archive/storage/persistent-storage.md). * Read the [Persistent Storage design document](https://git.k8s.io/design-proposals-archive/storage/persistent-storage.md).
@ -290,7 +291,3 @@ PersistentVolume are not present on the Pod resource itself.
* [PersistentVolumeSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumespec-v1-core) * [PersistentVolumeSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumespec-v1-core)
* [PersistentVolumeClaim](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaim-v1-core) * [PersistentVolumeClaim](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaim-v1-core)
* [PersistentVolumeClaimSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaimspec-v1-core) * [PersistentVolumeClaimSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaimspec-v1-core)

View File

@ -15,7 +15,8 @@ ConfigMaps are a Kubernetes mechanism that let you inject configuration data int
The ConfigMap concept allow you to decouple configuration artifacts from image content to The ConfigMap concept allow you to decouple configuration artifacts from image content to
keep containerized applications portable. For example, you can download and run the same keep containerized applications portable. For example, you can download and run the same
{{< glossary_tooltip text="container image" term_id="image" >}} to spin up containers for the purposes of local development, system test, or running a live end-user workload. {{< glossary_tooltip text="container image" term_id="image" >}} to spin up containers for
the purposes of local development, system test, or running a live end-user workload.
This page provides a series of usage examples demonstrating how to create ConfigMaps and This page provides a series of usage examples demonstrating how to create ConfigMaps and
configure Pods using data stored in ConfigMaps. configure Pods using data stored in ConfigMaps.
@ -30,7 +31,6 @@ step that downloads example data.
<!-- steps --> <!-- steps -->
## Create a ConfigMap ## Create a ConfigMap
You can use either `kubectl create configmap` or a ConfigMap generator in `kustomization.yaml` You can use either `kubectl create configmap` or a ConfigMap generator in `kustomization.yaml`
@ -66,15 +66,15 @@ whose filename is a valid key in the directory and packages each of those files
ConfigMap. Any directory entries except regular files are ignored (for example: subdirectories, ConfigMap. Any directory entries except regular files are ignored (for example: subdirectories,
symlinks, devices, pipes, and more). symlinks, devices, pipes, and more).
{{< note >}} {{< note >}}
Each filename being used for ConfigMap creation must consist of only acceptable characters, which are: letters (`A` to `Z` and `a` to z`), digits (`0` to `9`), '-', '_', or '.'. Each filename being used for ConfigMap creation must consist of only acceptable characters,
If you use `kubectl create configmap` with a directory where any of the file names contains an unacceptable character, the `kubectl` command may fail. which are: letters (`A` to `Z` and `a` to z`), digits (`0` to `9`), '-', '_', or '.'.
If you use `kubectl create configmap` with a directory where any of the file names contains
an unacceptable character, the `kubectl` command may fail.
The `kubectl` command does not print an error when it encounters an invalid filename. The `kubectl` command does not print an error when it encounters an invalid filename.
{{< /note >}} {{< /note >}}
Create the local directory: Create the local directory:
```shell ```shell
@ -396,7 +396,6 @@ data:
special.type: charm special.type: charm
``` ```
### Create a ConfigMap from generator ### Create a ConfigMap from generator
You can also create a ConfigMap from generators and then apply it to create the object You can also create a ConfigMap from generators and then apply it to create the object
@ -543,7 +542,8 @@ section, and learn how to use these objects with Pods.
kubectl create configmap special-config --from-literal=special.how=very kubectl create configmap special-config --from-literal=special.how=very
``` ```
2. Assign the `special.how` value defined in the ConfigMap to the `SPECIAL_LEVEL_KEY` environment variable in the Pod specification. 2. Assign the `special.how` value defined in the ConfigMap to the `SPECIAL_LEVEL_KEY`
environment variable in the Pod specification.
{{< codenew file="pods/pod-single-configmap-env-variable.yaml" >}} {{< codenew file="pods/pod-single-configmap-env-variable.yaml" >}}
@ -597,7 +597,6 @@ Here is the manifest you will use:
kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml kubectl create -f https://kubernetes.io/examples/configmap/configmap-multikeys.yaml
``` ```
* Use `envFrom` to define all of the ConfigMap's data as container environment variables. The * Use `envFrom` to define all of the ConfigMap's data as container environment variables. The
key from the ConfigMap becomes the environment variable name in the Pod. key from the ConfigMap becomes the environment variable name in the Pod.
@ -627,7 +626,6 @@ For example, the following Pod manifest:
Create that Pod, by running: Create that Pod, by running:
```shell ```shell
kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-env-var-valueFrom.yaml kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-env-var-valueFrom.yaml
``` ```
@ -646,7 +644,7 @@ kubectl delete pod dapi-test-pod --now
## Add ConfigMap data to a Volume ## Add ConfigMap data to a Volume
As explained in [Create ConfigMaps from files](#create-configmaps-from-files), when you create As explained in [Create ConfigMaps from files](#create-configmaps-from-files), when you create
a ConfigMap using ``--from-file``, the filename becomes a key stored in the `data` section of a ConfigMap using `--from-file`, the filename becomes a key stored in the `data` section of
the ConfigMap. The file contents become the key's value. the ConfigMap. The file contents become the key's value.
The examples in this section refer to a ConfigMap named `special-config`: The examples in this section refer to a ConfigMap named `special-config`:
@ -682,7 +680,8 @@ SPECIAL_TYPE
``` ```
Text data is exposed as files using the UTF-8 character encoding. To use some other Text data is exposed as files using the UTF-8 character encoding. To use some other
character encoding, use `binaryData` (see [ConfigMap object](/docs/concepts/configuration/configmap/#configmap-object) for more details). character encoding, use `binaryData`
(see [ConfigMap object](/docs/concepts/configuration/configmap/#configmap-object) for more details).
{{< note >}} {{< note >}}
If there are any files in the `/etc/config` directory of that container image, the volume If there are any files in the `/etc/config` directory of that container image, the volume
@ -722,7 +721,6 @@ Delete that Pod:
kubectl delete pod dapi-test-pod --now kubectl delete pod dapi-test-pod --now
``` ```
### Project keys to specific paths and file permissions ### Project keys to specific paths and file permissions
You can project keys to specific paths and specific permissions on a per-file You can project keys to specific paths and specific permissions on a per-file
@ -732,7 +730,7 @@ guide explains the syntax.
### Optional references ### Optional references
A ConfigMap reference may be marked _optional_. If the ConfigMap is non-existent, the mounted A ConfigMap reference may be marked _optional_. If the ConfigMap is non-existent, the mounted
volume will be empty. If the ConfigMap exists, but the referenced key is non-existent, the path volume will be empty. If the ConfigMap exists, but the referenced key is non-existent, the path
will be absent beneath the mount point. See [Optional ConfigMaps](#optional-configmaps) for more will be absent beneath the mount point. See [Optional ConfigMaps](#optional-configmaps) for more
details. details.
@ -751,7 +749,8 @@ minute by default) + TTL of ConfigMaps cache (1 minute by default) in kubelet. Y
can trigger an immediate refresh by updating one of the pod's annotations. can trigger an immediate refresh by updating one of the pod's annotations.
{{< note >}} {{< note >}}
A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath) volume will not receive ConfigMap updates. A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath)
volume will not receive ConfigMap updates.
{{< /note >}} {{< /note >}}
<!-- discussion --> <!-- discussion -->
@ -821,7 +820,7 @@ spec:
containers: containers:
- name: test-container - name: test-container
image: gcr.io/google_containers/busybox image: gcr.io/google_containers/busybox
command: [ "/bin/sh", "-c", "env" ] command: ["/bin/sh", "-c", "env"]
env: env:
- name: SPECIAL_LEVEL_KEY - name: SPECIAL_LEVEL_KEY
valueFrom: valueFrom:
@ -850,7 +849,7 @@ spec:
containers: containers:
- name: test-container - name: test-container
image: gcr.io/google_containers/busybox image: gcr.io/google_containers/busybox
command: [ "/bin/sh", "-c", "ls /etc/config" ] command: ["/bin/sh", "-c", "ls /etc/config"]
volumeMounts: volumeMounts:
- name: config-volume - name: config-volume
mountPath: /etc/config mountPath: /etc/config
@ -875,7 +874,8 @@ are projected to the pod can be as long as kubelet sync period (1 minute by defa
ConfigMaps cache (1 minute by default) in kubelet. ConfigMaps cache (1 minute by default) in kubelet.
{{< note >}} {{< note >}}
A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath) volume will not receive ConfigMap updates. A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes/#using-subpath)
volume will not receive ConfigMap updates.
{{< /note >}} {{< /note >}}
## Restrictions ## Restrictions
@ -926,7 +926,6 @@ kubectl delete configmap -l 'game-config in (config-4,config-5)
If you created a directory `configure-pod-container` and no longer need it, you should remove that too, If you created a directory `configure-pod-container` and no longer need it, you should remove that too,
or move it into the trash can / deleted files location. or move it into the trash can / deleted files location.
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
* Follow a real world example of * Follow a real world example of

View File

@ -5,18 +5,14 @@ weight: 170
--- ---
<!-- overview --> <!-- overview -->
This page shows how to use an Init Container to initialize a Pod before an This page shows how to use an Init Container to initialize a Pod before an
application Container runs. application Container runs.
## {{% heading "prerequisites" %}} ## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps --> <!-- steps -->
## Create a Pod that has an Init Container ## Create a Pod that has an Init Container
@ -37,55 +33,63 @@ shared Volume at `/work-dir`, and the application container mounts the shared
Volume at `/usr/share/nginx/html`. The init container runs the following command Volume at `/usr/share/nginx/html`. The init container runs the following command
and then terminates: and then terminates:
wget -O /work-dir/index.html http://info.cern.ch ```shell
wget -O /work-dir/index.html http://info.cern.ch
```
Notice that the init container writes the `index.html` file in the root directory Notice that the init container writes the `index.html` file in the root directory
of the nginx server. of the nginx server.
Create the Pod: Create the Pod:
kubectl apply -f https://k8s.io/examples/pods/init-containers.yaml ```shell
kubectl apply -f https://k8s.io/examples/pods/init-containers.yaml
```
Verify that the nginx container is running: Verify that the nginx container is running:
kubectl get pod init-demo ```shell
kubectl get pod init-demo
```
The output shows that the nginx container is running: The output shows that the nginx container is running:
NAME READY STATUS RESTARTS AGE ```
init-demo 1/1 Running 0 1m NAME READY STATUS RESTARTS AGE
init-demo 1/1 Running 0 1m
```
Get a shell into the nginx container running in the init-demo Pod: Get a shell into the nginx container running in the init-demo Pod:
kubectl exec -it init-demo -- /bin/bash ```shell
kubectl exec -it init-demo -- /bin/bash
```
In your shell, send a GET request to the nginx server: In your shell, send a GET request to the nginx server:
root@nginx:~# apt-get update ```
root@nginx:~# apt-get install curl root@nginx:~# apt-get update
root@nginx:~# curl localhost root@nginx:~# apt-get install curl
root@nginx:~# curl localhost
```
The output shows that nginx is serving the web page that was written by the init container: The output shows that nginx is serving the web page that was written by the init container:
<html><head></head><body><header> ```html
<title>http://info.cern.ch</title> <html><head></head><body><header>
</header> <title>http://info.cern.ch</title>
</header>
<h1>http://info.cern.ch - home of the first website</h1>
...
<li><a href="http://info.cern.ch/hypertext/WWW/TheProject.html">Browse the first website</a></li>
...
<h1>http://info.cern.ch - home of the first website</h1>
...
<li><a href="http://info.cern.ch/hypertext/WWW/TheProject.html">Browse the first website</a></li>
...
```
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
* Learn more about * Learn more about
[communicating between Containers running in the same Pod](/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/). [communicating between Containers running in the same Pod](/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/).
* Learn more about [Init Containers](/docs/concepts/workloads/pods/init-containers/). * Learn more about [Init Containers](/docs/concepts/workloads/pods/init-containers/).
* Learn more about [Volumes](/docs/concepts/storage/volumes/). * Learn more about [Volumes](/docs/concepts/storage/volumes/).
* Learn more about [Debugging Init Containers](/docs/tasks/debug/debug-application/debug-init-containers/) * Learn more about [Debugging Init Containers](/docs/tasks/debug/debug-application/debug-init-containers/)