Clean zh/docs directory for dangling YAML files (#17341)
There are many YAML manifests sneaking into the `zh/docs/` directory. These files should go to the `zh/examples` directory instead. Having these "garbage" files (not referenced anywhere) is creating confusion for the release meister when merging branches. For example, some YAML files found in the 'master' branch are no longer there in the release-1.16 branch. It is tedious, if possible at all, to solve all this kind of conflicts during a rebase. The PR cleanses the zh/docs directory for all dangling YAML files.
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: command-demo
|
||||
labels:
|
||||
purpose: demonstrate-command
|
||||
spec:
|
||||
containers:
|
||||
- name: command-demo-container
|
||||
image: debian
|
||||
command: ["printenv"]
|
||||
args: ["HOSTNAME", "KUBERNETES_PORT"]
|
||||
restartPolicy: OnFailure
|
||||
@@ -1,45 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: dapi-envars-resourcefieldref
|
||||
spec:
|
||||
containers:
|
||||
- name: test-container
|
||||
image: k8s.gcr.io/busybox:1.24
|
||||
command: [ "sh", "-c"]
|
||||
args:
|
||||
- while true; do
|
||||
echo -en '\n';
|
||||
printenv MY_CPU_REQUEST MY_CPU_LIMIT;
|
||||
printenv MY_MEM_REQUEST MY_MEM_LIMIT;
|
||||
sleep 10;
|
||||
done;
|
||||
resources:
|
||||
requests:
|
||||
memory: "32Mi"
|
||||
cpu: "125m"
|
||||
limits:
|
||||
memory: "64Mi"
|
||||
cpu: "250m"
|
||||
env:
|
||||
- name: MY_CPU_REQUEST
|
||||
valueFrom:
|
||||
resourceFieldRef:
|
||||
containerName: test-container
|
||||
resource: requests.cpu
|
||||
- name: MY_CPU_LIMIT
|
||||
valueFrom:
|
||||
resourceFieldRef:
|
||||
containerName: test-container
|
||||
resource: limits.cpu
|
||||
- name: MY_MEM_REQUEST
|
||||
valueFrom:
|
||||
resourceFieldRef:
|
||||
containerName: test-container
|
||||
resource: requests.memory
|
||||
- name: MY_MEM_LIMIT
|
||||
valueFrom:
|
||||
resourceFieldRef:
|
||||
containerName: test-container
|
||||
resource: limits.memory
|
||||
restartPolicy: Never
|
||||
@@ -1,38 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: dapi-envars-fieldref
|
||||
spec:
|
||||
containers:
|
||||
- name: test-container
|
||||
image: k8s.gcr.io/busybox
|
||||
command: [ "sh", "-c"]
|
||||
args:
|
||||
- while true; do
|
||||
echo -en '\n';
|
||||
printenv MY_NODE_NAME MY_POD_NAME MY_POD_NAMESPACE;
|
||||
printenv MY_POD_IP MY_POD_SERVICE_ACCOUNT;
|
||||
sleep 10;
|
||||
done;
|
||||
env:
|
||||
- name: MY_NODE_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: spec.nodeName
|
||||
- name: MY_POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: MY_POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
- name: MY_POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: MY_POD_SERVICE_ACCOUNT
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: spec.serviceAccountName
|
||||
restartPolicy: Never
|
||||
@@ -1,54 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: kubernetes-downwardapi-volume-example-2
|
||||
spec:
|
||||
containers:
|
||||
- name: client-container
|
||||
image: k8s.gcr.io/busybox:1.24
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- while true; do
|
||||
echo -en '\n';
|
||||
if [[ -e /etc/podinfo/cpu_limit ]]; then
|
||||
echo -en '\n'; cat /etc/podinfo/cpu_limit; fi;
|
||||
if [[ -e /etc/cpu_request ]]; then
|
||||
echo -en '\n'; cat /etc/podinfo/cpu_request; fi;
|
||||
if [[ -e /etc/mem_limit ]]; then
|
||||
echo -en '\n'; cat /etc/podinfo/mem_limit; fi;
|
||||
if [[ -e /etc/mem_request ]]; then
|
||||
echo -en '\n'; cat /etc/podinfo/mem_request; fi;
|
||||
sleep 5;
|
||||
done;
|
||||
resources:
|
||||
requests:
|
||||
memory: "32Mi"
|
||||
cpu: "125m"
|
||||
limits:
|
||||
memory: "64Mi"
|
||||
cpu: "250m"
|
||||
volumeMounts:
|
||||
- name: podinfo
|
||||
mountPath: /etc/podinfo
|
||||
readOnly: false
|
||||
volumes:
|
||||
- name: podinfo
|
||||
downwardAPI:
|
||||
items:
|
||||
- path: "cpu_limit"
|
||||
resourceFieldRef:
|
||||
containerName: client-container
|
||||
resource: limits.cpu
|
||||
- path: "cpu_request"
|
||||
resourceFieldRef:
|
||||
containerName: client-container
|
||||
resource: requests.cpu
|
||||
- path: "mem_limit"
|
||||
resourceFieldRef:
|
||||
containerName: client-container
|
||||
resource: limits.memory
|
||||
- path: "mem_request"
|
||||
resourceFieldRef:
|
||||
containerName: client-container
|
||||
resource: requests.memory
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: kubernetes-downwardapi-volume-example
|
||||
labels:
|
||||
zone: us-est-coast
|
||||
cluster: test-cluster1
|
||||
rack: rack-22
|
||||
annotations:
|
||||
build: two
|
||||
builder: john-doe
|
||||
spec:
|
||||
containers:
|
||||
- name: client-container
|
||||
image: k8s.gcr.io/busybox
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- while true; do
|
||||
if [[ -e /etc/podinfo/labels ]]; then
|
||||
echo -en '\n\n'; cat /etc/podinfo/labels; fi;
|
||||
if [[ -e /etc/podinfo/annotations ]]; then
|
||||
echo -en '\n\n'; cat /etc/podinfo/annotations; fi;
|
||||
sleep 5;
|
||||
done;
|
||||
volumeMounts:
|
||||
- name: podinfo
|
||||
mountPath: /etc/podinfo
|
||||
readOnly: false
|
||||
volumes:
|
||||
- name: podinfo
|
||||
downwardAPI:
|
||||
items:
|
||||
- path: "labels"
|
||||
fieldRef:
|
||||
fieldPath: metadata.labels
|
||||
- path: "annotations"
|
||||
fieldRef:
|
||||
fieldPath: metadata.annotations
|
||||
|
||||
+23
-25
@@ -31,21 +31,19 @@ content_template: templates/task
|
||||
|
||||
本示例中,将创建一个只包含单个容器的Pod。在Pod配置文件中设置了一个命令与两个入参:
|
||||
|
||||
{{< code file="commands.yaml" >}}
|
||||
{{< codenew file="pods/commands.yaml" >}}
|
||||
|
||||
1. 基于YAML文件创建一个Pod:
|
||||
1. 基于 YAML 文件创建一个 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/commands.yaml
|
||||
kubectl apply -f https://k8s.io/examples/pods/commands.yaml
|
||||
```
|
||||
|
||||
2. List the running Pods:
|
||||
2. 列举运行中的 Pods:
|
||||
|
||||
获取正在运行的 pod
|
||||
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
查询结果显示在command-demo这个Pod下运行的容器已经启动完成
|
||||
|
||||
@@ -55,7 +53,7 @@ content_template: templates/task
|
||||
kubectl logs command-demo
|
||||
```
|
||||
|
||||
日志中显示了HOSTNAME 与KUBERNETES_PORT 这两个环境变量的值:
|
||||
日志中显示了 HOSTNAME 与 KUBERNETES_PORT 这两个环境变量的值:
|
||||
|
||||
```
|
||||
command-demo
|
||||
@@ -99,12 +97,12 @@ args: ["-c", "while true; do echo hello; sleep 10;done"]
|
||||
|
||||
下表给出了Docker 与 Kubernetes中对应的字段名称。
|
||||
|
||||
| Description | Docker field name | Kubernetes field name |
|
||||
|----------------------------------------|------------------------|-----------------------|
|
||||
| The command run by the container | Entrypoint | command |
|
||||
| The arguments passed to the command | Cmd | args |
|
||||
| 描述 | Docker 字段名称 | Kubernetes 字段名称 |
|
||||
|------|-----------------|---------------------|
|
||||
| 容器运行的命令 | Entrypoint | command |
|
||||
| 传递给命令的参数集合 | Cmd | args |
|
||||
|
||||
如果要覆盖默认的Entrypoint 与 Cmd,需要遵循如下规则:
|
||||
如果要覆盖默认的 Entrypoint 与 Cmd,需要遵循如下规则:
|
||||
|
||||
* 如果在容器配置中没有设置`command` 或者 `args`,那么将使用Docker镜像自带的命
|
||||
令及其入参。
|
||||
@@ -121,22 +119,22 @@ args: ["-c", "while true; do echo hello; sleep 10;done"]
|
||||
|
||||
下表涵盖了各类设置场景:
|
||||
|
||||
| Image Entrypoint | Image Cmd | Container command | Container args | Command run |
|
||||
|--------------------|------------------|---------------------|--------------------|------------------|
|
||||
| `[/ep-1]` | `[foo bar]` | <not set> | <not set> | `[ep-1 foo bar]` |
|
||||
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | <not set> | `[ep-2]` |
|
||||
| `[/ep-1]` | `[foo bar]` | <not set> | `[zoo boo]` | `[ep-1 zoo boo]` |
|
||||
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | `[zoo boo]` | `[ep-2 zoo boo]` |
|
||||
| 镜像 Entrypoint | 镜像 Cmd | 容器命令 | 容器参数 | 运行的命令 |
|
||||
|-------------------|----------|----------|----------|------------|
|
||||
| `[/ep-1]` | `[foo bar]` | <not set> | <not set> | `[ep-1 foo bar]` |
|
||||
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | <not set> | `[ep-2]` |
|
||||
| `[/ep-1]` | `[foo bar]` | <not set> | `[zoo boo]` | `[ep-1 zoo boo]` |
|
||||
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | `[zoo boo]` | `[ep-2 zoo boo]` |
|
||||
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture whatsnext %}}
|
||||
|
||||
* 获取更多资讯可参考 [containers and commands](/docs/user-guide/containers/).
|
||||
* 获取更多资讯可参考 [configuring pods and containers](/docs/tasks/).
|
||||
* 获取更多资讯可参考 [running commands in a container](/docs/tasks/debug-application-cluster/get-shell-running-container/).
|
||||
* 参考 [Container](/docs/api-reference/{{< param "version" >}}/#container-v1-core).
|
||||
* 深入了解 [容器和命令](/docs/user-guide/containers/).
|
||||
* 深入了解 [配置 Pods 和容器](/docs/tasks/).
|
||||
* 深入了解 [在容器中运行命令](/docs/tasks/debug-application-cluster/get-shell-running-container/).
|
||||
* 参考 [Container](/docs/api-reference/{{< param "version" >}}/#container-v1-core) 资源
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
+2
-2
@@ -26,12 +26,12 @@ content_template: templates/task
|
||||
本示例中,将创建一个只包含单个容器的Pod。Pod的配置文件中设置环境变量的名称为`DEMO_GREETING`,
|
||||
其值为`"Hello from the environment"`。下面是Pod的配置文件内容:
|
||||
|
||||
{{< code file="envars.yaml" >}}
|
||||
{{< codenew file="pods/inject/envars.yaml" >}}
|
||||
|
||||
1. 基于YAML文件创建一个Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/docs/tasks/inject-data-application/envars.yaml
|
||||
kubectl apply -f https://k8s.io/examples/pods/inject/envars.yaml
|
||||
```
|
||||
|
||||
1. 获取一下当前正在运行的Pods信息:
|
||||
|
||||
+4
-4
@@ -31,7 +31,7 @@ content_template: templates/task
|
||||
|
||||
在这个练习中,你将创建一个包含一个容器的pod。这是该pod的配置文件:
|
||||
|
||||
{{< code file="dapi-volume.yaml" >}}
|
||||
{{< codenew file="pods/inject/dapi-volume.yaml" >}}
|
||||
|
||||
在配置文件中,你可以看到Pod有一个`downwardAPI`类型的Volume,并且挂载到容器中的`/etc`。
|
||||
|
||||
@@ -46,7 +46,7 @@ content_template: templates/task
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/cn/docs/tasks/inject-data-application/dapi-volume.yaml
|
||||
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume.yaml
|
||||
```
|
||||
|
||||
验证Pod中的容器运行正常:
|
||||
@@ -134,7 +134,7 @@ total 8
|
||||
|
||||
前面的练习中,你将Pod字段保存到DownwardAPIVolumeFile中。接下来这个练习,你将存储容器字段。这里是包含一个容器的pod的配置文件:
|
||||
|
||||
{{< code file="dapi-volume-resources.yaml" >}}
|
||||
{{< codenew file="pods/inject/dapi-volume-resources.yaml" >}}
|
||||
|
||||
在这个配置文件中,你可以看到Pod有一个`downwardAPI`类型的Volume,并且挂载到容器的`/etc`目录。
|
||||
|
||||
@@ -145,7 +145,7 @@ total 8
|
||||
创建Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/cn/docs/tasks/inject-data-application/dapi-volume-resources.yaml
|
||||
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-volume-resources.yaml
|
||||
```
|
||||
|
||||
进入Pod中运行的容器,打开一个shell:
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: envar-demo
|
||||
labels:
|
||||
purpose: demonstrate-envars
|
||||
spec:
|
||||
containers:
|
||||
- name: envar-demo-container
|
||||
image: gcr.io/google-samples/node-hello:1.0
|
||||
env:
|
||||
- name: DEMO_GREETING
|
||||
value: "Hello from the environment"
|
||||
+4
-4
@@ -37,7 +37,7 @@ content_template: templates/task
|
||||
|
||||
在这个练习中,你将创建一个包含一个容器的pod。这是该pod的配置文件:
|
||||
|
||||
{{< code file="dapi-envars-pod.yaml" >}}
|
||||
{{< codenew file="pods/inject/dapi-envars-pod.yaml" >}}
|
||||
|
||||
这个配置文件中,你可以看到五个环境变量。`env`字段是一个[EnvVars](/docs/resources-reference/{{< param "version" >}}/#envvar-v1-core)类型的数组。
|
||||
数组中第一个元素指定`MY_NODE_NAME`这个环境变量从Pod的`spec.nodeName`字段获取变量值。同样,其它环境变量也是从Pod的字段获取它们的变量值。
|
||||
@@ -49,7 +49,7 @@ content_template: templates/task
|
||||
创建Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/cn/docs/tasks/inject-data-application/dapi-envars-pod.yaml
|
||||
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-envars-pod.yaml
|
||||
```
|
||||
|
||||
验证Pod中的容器运行正常:
|
||||
@@ -105,7 +105,7 @@ MY_POD_NAME=dapi-envars-fieldref
|
||||
|
||||
前面的练习中,你将Pod字段作为环境变量的值。接下来这个练习,你将用容器字段作为环境变量的值。这里是包含一个容器的pod的配置文件:
|
||||
|
||||
{{< code file="dapi-envars-container.yaml" >}}
|
||||
{{< codenew file="pods/inject/dapi-envars-container.yaml" >}}
|
||||
|
||||
这个配置文件中,你可以看到四个环境变量。`env`字段是一个[EnvVars](/docs/resources-reference/{{< param "version" >}}/#envvar-v1-core)
|
||||
类型的数组。数组中第一个元素指定`MY_CPU_REQUEST`这个环境变量从容器的`requests.cpu`字段获取变量值。同样,其它环境变量也是从容器的字段获取它们的变量值。
|
||||
@@ -113,7 +113,7 @@ MY_POD_NAME=dapi-envars-fieldref
|
||||
创建Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/cn/docs/tasks/inject-data-application/dapi-envars-container.yaml
|
||||
kubectl apply -f https://k8s.io/examples/pods/inject/dapi-envars-container.yaml
|
||||
```
|
||||
|
||||
验证Pod中的容器运行正常:
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: website
|
||||
labels:
|
||||
app: website
|
||||
role: frontend
|
||||
annotations:
|
||||
podpreset.admission.kubernetes.io/podpreset-allow-database: "resource version"
|
||||
spec:
|
||||
containers:
|
||||
- name: website
|
||||
image: ecorp/website
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
- mountPath: /etc/app/config.json
|
||||
readOnly: true
|
||||
name: secret-volume
|
||||
ports:
|
||||
- containerPort: 80
|
||||
env:
|
||||
- name: DB_PORT
|
||||
value: "6379"
|
||||
- name: duplicate_key
|
||||
value: FROM_ENV
|
||||
- name: expansion
|
||||
value: $(REPLACE_ME)
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: etcd-env-config
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
- name: secret-volume
|
||||
secret:
|
||||
secretName: config-details
|
||||
@@ -1,31 +0,0 @@
|
||||
apiVersion: settings.k8s.io/v1alpha1
|
||||
kind: PodPreset
|
||||
metadata:
|
||||
name: allow-database
|
||||
namespace: myns
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
role: frontend
|
||||
env:
|
||||
- name: DB_PORT
|
||||
value: 6379
|
||||
- name: duplicate_key
|
||||
value: FROM_ENV
|
||||
- name: expansion
|
||||
value: $(REPLACE_ME)
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: etcd-env-config
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
- mountPath: /etc/app/config.json
|
||||
readOnly: true
|
||||
name: secret-volume
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
- name: secret-volume
|
||||
secret:
|
||||
secretName: config-details
|
||||
@@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: etcd-env-config
|
||||
data:
|
||||
number_of_members: "1"
|
||||
initial_cluster_state: new
|
||||
initial_cluster_token: DUMMY_ETCD_INITIAL_CLUSTER_TOKEN
|
||||
discovery_token: DUMMY_ETCD_DISCOVERY_TOKEN
|
||||
discovery_url: http://etcd_discovery:2379
|
||||
etcdctl_peers: http://etcd:2379
|
||||
duplicate_key: FROM_CONFIG_MAP
|
||||
REPLACE_ME: "a value"
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: website
|
||||
labels:
|
||||
app: website
|
||||
role: frontend
|
||||
spec:
|
||||
containers:
|
||||
- name: website
|
||||
image: ecorp/website
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
ports:
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
- containerPort: 80
|
||||
@@ -1,19 +0,0 @@
|
||||
apiVersion: settings.k8s.io/v1alpha1
|
||||
kind: PodPreset
|
||||
metadata:
|
||||
name: allow-database
|
||||
namespace: myns
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
role: frontend
|
||||
env:
|
||||
- name: DB_PORT
|
||||
value: "6379"
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: other-volume
|
||||
volumes:
|
||||
- name: other-volume
|
||||
emptyDir: {}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: website
|
||||
labels:
|
||||
app: website
|
||||
role: frontend
|
||||
annotations:
|
||||
podpreset.admission.kubernetes.io/podpreset-allow-database: "resource version"
|
||||
spec:
|
||||
containers:
|
||||
- name: website
|
||||
image: ecorp/website
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
ports:
|
||||
- containerPort: 80
|
||||
env:
|
||||
- name: DB_PORT
|
||||
value: "6379"
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: website
|
||||
labels:
|
||||
app: website
|
||||
role: frontend
|
||||
annotations:
|
||||
podpreset.admission.kubernetes.io/podpreset-allow-database: "resource version"
|
||||
podpreset.admission.kubernetes.io/podpreset-proxy: "resource version"
|
||||
spec:
|
||||
containers:
|
||||
- name: website
|
||||
image: ecorp/website
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
- mountPath: /etc/proxy/configs
|
||||
name: proxy-volume
|
||||
ports:
|
||||
- containerPort: 80
|
||||
env:
|
||||
- name: DB_PORT
|
||||
value: "6379"
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
- name: proxy-volume
|
||||
emptyDir: {}
|
||||
@@ -1,14 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: website
|
||||
labels:
|
||||
app: website
|
||||
role: frontend
|
||||
spec:
|
||||
containers:
|
||||
- name: website
|
||||
image: ecorp/website
|
||||
ports:
|
||||
- containerPort: 80
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
apiVersion: settings.k8s.io/v1alpha1
|
||||
kind: PodPreset
|
||||
metadata:
|
||||
name: allow-database
|
||||
namespace: myns
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
role: frontend
|
||||
env:
|
||||
- name: DB_PORT
|
||||
value: "6379"
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
@@ -1,15 +0,0 @@
|
||||
apiVersion: settings.k8s.io/v1alpha1
|
||||
kind: PodPreset
|
||||
metadata:
|
||||
name: proxy
|
||||
namespace: myns
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
role: frontend
|
||||
volumeMounts:
|
||||
- mountPath: /etc/proxy/configs
|
||||
name: proxy-volume
|
||||
volumes:
|
||||
- name: proxy-volume
|
||||
emptyDir: {}
|
||||
@@ -1,30 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
app: guestbook
|
||||
tier: frontend
|
||||
annotations:
|
||||
podpreset.admission.kubernetes.io/podpreset-allow-database: "resource version"
|
||||
spec:
|
||||
containers:
|
||||
- name: php-redis
|
||||
image: gcr.io/google_samples/gb-frontend:v3
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 100Mi
|
||||
volumeMounts:
|
||||
- mountPath: /cache
|
||||
name: cache-volume
|
||||
env:
|
||||
- name: GET_HOSTS_FROM
|
||||
value: dns
|
||||
- name: DB_PORT
|
||||
value: "6379"
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumes:
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
apiVersion: apps/v1beta2
|
||||
kind: ReplicaSet
|
||||
metadata:
|
||||
name: frontend
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
tier: frontend
|
||||
matchExpressions:
|
||||
- {key: tier, operator: In, values: [frontend]}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: guestbook
|
||||
tier: frontend
|
||||
spec:
|
||||
containers:
|
||||
- name: php-redis
|
||||
image: gcr.io/google_samples/gb-frontend:v3
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 100Mi
|
||||
env:
|
||||
- name: GET_HOSTS_FROM
|
||||
value: dns
|
||||
ports:
|
||||
- containerPort: 80
|
||||
@@ -16,37 +16,76 @@ title: 使用 PodPreset 将信息注入 Pods
|
||||
|
||||
这里是一个简单的示例,展示了如何通过 Pod Preset 修改 Pod spec 。
|
||||
|
||||
**用户提交的 pod spec:**
|
||||
{{< codenew file="podpreset/preset.yaml" >}}
|
||||
|
||||
{{< code file="podpreset-pod.yaml" >}}
|
||||
创建 PodPreset:
|
||||
|
||||
**Pod Preset 示例:**
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/podpreset/preset.yaml
|
||||
```
|
||||
|
||||
{{< code file="podpreset-preset.yaml" >}}
|
||||
检查所创建的 PodPreset:
|
||||
|
||||
**通过准入控制器后的 Pod spec:**
|
||||
```shell
|
||||
kubectl get podpreset
|
||||
```
|
||||
```
|
||||
NAME AGE
|
||||
allow-database 1m
|
||||
```
|
||||
|
||||
{{< code file="podpreset-merged.yaml" >}}
|
||||
|
||||
### 带有 `ConfigMap` 的 Pod Spec 示例
|
||||
|
||||
这里的示例展示了如何通过 Pod Preset 修改 Pod spec,Pod Preset 中定义了 `ConfigMap` 作为环境变量取值来源。
|
||||
新的 PodPreset 会对所有具有标签 `role: frontend` 的 Pods 采取行动。
|
||||
|
||||
**用户提交的 pod spec:**
|
||||
|
||||
{{< code file="podpreset-pod.yaml" >}}
|
||||
{{< codenew file="podpreset/pod.yaml" >}}
|
||||
|
||||
创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl create -f https://k8s.io/examples/podpreset/pod.yaml
|
||||
```
|
||||
|
||||
列举运行中的 Pods:
|
||||
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
website 1/1 Running 0 4m
|
||||
```
|
||||
|
||||
**通过准入控制器后的 Pod 规约:**
|
||||
|
||||
{{< codenew file="podpreset/merged.yaml" >}}
|
||||
|
||||
要查看如上输出,运行下面的命令:
|
||||
|
||||
```shell
|
||||
kubectl get pod website -o yaml
|
||||
```
|
||||
|
||||
### 带有 ConfigMap 的 Pod Spec 示例
|
||||
|
||||
这里的示例展示了如何通过 PodPreset 修改 Pod 规约,PodPreset 中定义了 `ConfigMap`
|
||||
作为环境变量取值来源。
|
||||
|
||||
**用户提交的 pod spec:**
|
||||
|
||||
{{< codenew file="podpreset/pod.yaml" >}}
|
||||
|
||||
**用户提交的 `ConfigMap`:**
|
||||
|
||||
{{< code file="podpreset-configmap.yaml" >}}
|
||||
{{< codenew file="podpreset/configmap.yaml" >}}
|
||||
|
||||
**Pod Preset 示例:**
|
||||
**PodPreset 示例:**
|
||||
|
||||
{{< code file="podpreset-allow-db.yaml" >}}
|
||||
{{< codenew file="podpreset/allow-db.yaml" >}}
|
||||
|
||||
**通过准入控制器后的 Pod spec:**
|
||||
|
||||
{{< code file="podpreset-allow-db-merged.yaml" >}}
|
||||
{{< codenew file="podpreset/allow-db-merged.yaml" >}}
|
||||
|
||||
### 带有 Pod Spec 的 ReplicaSet 示例
|
||||
|
||||
@@ -54,53 +93,53 @@ title: 使用 PodPreset 将信息注入 Pods
|
||||
|
||||
**用户提交的 ReplicaSet:**
|
||||
|
||||
{{< code file="podpreset-replicaset.yaml" >}}
|
||||
{{< codenew file="podpreset/replicaset.yaml" >}}
|
||||
|
||||
**Pod Preset 示例:**
|
||||
**PodPreset 示例:**
|
||||
|
||||
{{< code file="podpreset-preset.yaml" >}}
|
||||
{{< codenew file="podpreset/preset.yaml" >}}
|
||||
|
||||
**通过准入控制器后的 Pod spec:**
|
||||
|
||||
注意 ReplicaSet spec 没有改变,用户必须检查单独的 pod 来验证 PodPreset 已被应用。
|
||||
|
||||
{{< code file="podpreset-replicaset-merged.yaml" >}}
|
||||
{{< codenew file="podpreset/replicaset-merged.yaml" >}}
|
||||
|
||||
### 多 PodPreset 示例
|
||||
|
||||
这里的示例展示了如何通过多个 Pod 注入策略修改 Pod spec。
|
||||
|
||||
**用户提交的 pod spec:**
|
||||
**用户提交的 Pod 规约:**
|
||||
|
||||
{{< code file="podpreset-pod.yaml" >}}
|
||||
{{< codenew file="podpreset/pod.yaml" >}}
|
||||
|
||||
**Pod Preset 示例:**
|
||||
**PodPreset 示例:**
|
||||
|
||||
{{< code file="podpreset-preset.yaml" >}}
|
||||
{{< codenew file="podpreset/preset.yaml" >}}
|
||||
|
||||
**另一个 Pod Preset 示例:**
|
||||
|
||||
{{< code file="podpreset-proxy.yaml" >}}
|
||||
{{< codenew file="podpreset/proxy.yaml" >}}
|
||||
|
||||
**通过准入控制器后的 Pod spec:**
|
||||
**通过准入控制器后的 Pod 规约:**
|
||||
|
||||
{{< code file="podpreset-multi-merged.yaml" >}}
|
||||
{{< codenew file="podpreset/multi-merged.yaml" >}}
|
||||
|
||||
### 冲突示例
|
||||
|
||||
这里的示例展示了 Pod Preset 与原 Pod 存在冲突时,Pod spec 不会被修改。
|
||||
这里的示例展示了 PodPreset 与原 Pod 存在冲突时,Pod spec 不会被修改。
|
||||
|
||||
**用户提交的 pod spec:**
|
||||
**用户提交的 Pod 规约:**
|
||||
|
||||
{{< code file="podpreset-conflict-pod.yaml" >}}
|
||||
{{< codenew file="podpreset/conflict-pod.yaml" >}}
|
||||
|
||||
**Pod Preset 示例:**
|
||||
**PodPreset 示例:**
|
||||
|
||||
{{< code file="podpreset-conflict-preset.yaml" >}}
|
||||
{{< codenew file="podpreset/conflict-preset.yaml" >}}
|
||||
|
||||
**因存在冲突,通过准入控制器后的 Pod spec 不会改变:**
|
||||
|
||||
{{< code file="podpreset-conflict-pod.yaml" >}}
|
||||
{{< codenew file="podpreset/conflict-pod.yaml" >}}
|
||||
|
||||
**如果运行 `kubectl describe...` 用户会看到以下事件:**
|
||||
|
||||
@@ -117,7 +156,9 @@ Events:
|
||||
一旦用户不再需要 pod preset,可以使用 `kubectl` 进行删除:
|
||||
|
||||
```shell
|
||||
$ kubectl delete podpreset allow-database
|
||||
kubectl delete podpreset allow-database
|
||||
```
|
||||
```
|
||||
podpreset "allow-database" deleted
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user