Consolidate YAML files [part-14] (#9379)

This PR deals with the getting started guides (windows) and tutorials
sections. Since the YAML files in the windows directory currently are not
referenced at all, this PR refactored the markdown file to correct this
problem. When appropriate, we use the YAML content from the markdown in
the extracted version.
This commit is contained in:
Qiming 2018-07-04 14:58:20 +08:00 committed by k8s-ci-robot
parent ea6004bd4f
commit 3dd65e4e95
22 changed files with 180 additions and 294 deletions

View File

@ -261,112 +261,24 @@ The examples listed below assume running Windows nodes on Windows Server 1709. I
### Scheduling Pods on Windows
Because your cluster has both Linux and Windows nodes, you must explicitly set the `nodeSelector` constraint to be able to schedule pods to Windows nodes. You must set nodeSelector with the label `beta.kubernetes.io/os` to the value `windows`; see the following example:
```yaml
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "iis",
"labels": {
"name": "iis"
}
},
"spec": {
"containers": [
{
"name": "iis",
"image": "microsoft/iis:windowsservercore-1709",
"ports": [
{
"containerPort": 80
}
]
}
],
"nodeSelector": {
"beta.kubernetes.io/os": "windows"
}
}
}
```
{{< codenew file="windows/simple-pod.yaml" >}}
{{< note >}}
**Note:** This example assumes you are running on Windows Server 1709, so uses the image tag to support that. If you are on a different version, you will need to update the tag. For example, if on Windows Server 2016, update to use `"image": "microsoft/iis"` which will default to that OS version.
{{< /note >}}
### Secrets and ConfigMaps
Secrets and ConfigMaps can be utilized in Windows Server Containers, but must be used as environment variables. See limitations section below for additional details.
**Examples:**
Windows pod with secrets mapped to environment variables
```yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
username: YWRtaW4=
password: MWYyZDFlMmU2N2Rm
Windows pod with secrets mapped to environment variables
---
{{< codenew file="windows/secret-pod.yaml" >}}
apiVersion: v1
kind: Pod
metadata:
name: my-secret-pod
spec:
containers:
- name: my-secret-pod
image: microsoft/windowsservercore:1709
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: username
- name: PASSWORD
valueFrom:
secretKeyRef:
name: mysecret
key: password
nodeSelector:
beta.kubernetes.io/os: windows
```
Windows Pod with configMap values mapped to environment variables
Windows pod with configMap values mapped to environment variables
```yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: example-config
data:
example.property.1: hello
example.property.2: world
---
apiVersion: v1
kind: Pod
metadata:
name: my-configmap-pod
spec:
containers:
- name: my-configmap-pod
image: microsoft/windowsservercore:1709
env:
- name: EXAMPLE_PROPERTY_1
valueFrom:
configMapKeyRef:
name: example-config
key: example.property.1
- name: EXAMPLE_PROPERTY_2
valueFrom:
configMapKeyRef:
name: example-config
key: example.property.2
nodeSelector:
beta.kubernetes.io/os: windows
```
{{< codenew file="windows/configmap-pod.yaml" >}}
### Volumes
Some supported Volume Mounts are local, emptyDir, hostPath. One thing to remember is that paths must either be escaped, or use forward slashes, for example `mountPath: "C:\\etc\\foo"` or `mountPath: "C:/etc/foo"`.
@ -375,76 +287,19 @@ Persistent Volume Claims are supported for supported volume types.
**Examples:**
Windows pod with a hostPath volume
```yaml
apiVersion: v1
kind: Pod
metadata:
name: my-hostpath-volume-pod
spec:
containers:
- name: my-hostpath-volume-pod
image: microsoft/windowsservercore:1709
volumeMounts:
- name: foo
mountPath: "C:\\etc\\foo"
readOnly: true
nodeSelector:
beta.kubernetes.io/os: windows
volumes:
- name: foo
hostPath:
path: "C:\\etc\\foo"
```
Windows pod with a hostPath volume
Windows pod with multiple emptyDir volumes
{{< codenew file="windows/hostpath-volume-pod.yaml" >}}
```yaml
apiVersion: v1
kind: Pod
metadata:
name: my-empty-dir-pod
spec:
containers:
- image: microsoft/windowsservercore:1709
name: my-empty-dir-pod
volumeMounts:
- mountPath: /cache
name: cache-volume
- mountPath: C:/scratch
name: scratch-volume
volumes:
- name: cache-volume
emptyDir: {}
- name: scratch-volume
emptyDir: {}
nodeSelector:
beta.kubernetes.io/os: windows
```
Windows pod with multiple emptyDir volumes
{{< codenew file="windows/emptydir-pod.yaml" >}}
### DaemonSets
DaemonSets are supported
```yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: my-DaemonSet
labels:
app: foo
spec:
template:
metadata:
labels:
app: foo
spec:
containers:
- name: foo
image: microsoft/windowsservercore:1709
nodeSelector:
beta.kubernetes.io/os: windows
```
{{< codenew file="windows/daemonset.yaml" >}}
### Metrics
@ -454,53 +309,13 @@ Windows Stats use a hybrid model: pod and container level stats come from CRI (v
Container resources (CPU and memory) could be set now for windows containers in v1.10.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: iis
spec:
replicas: 3
template:
metadata:
labels:
app: iis
spec:
containers:
- name: iis
image: microsoft/iis
resources:
limits:
memory: "128Mi"
cpu: 2
ports:
- containerPort: 80
```
{{< codenew file="windows/deploy-resource.yaml" >}}
### Hyper-V Containers
Hyper-V containers are supported as experimental in v1.10. To create a Hyper-V container, kubelet should be started with feature gates `HyperVContainer=true` and Pod should include annotation `experimental.windows.kubernetes.io/isolation-type=hyperv`.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: iis
spec:
replicas: 3
template:
metadata:
labels:
app: iis
annotations:
experimental.windows.kubernetes.io/isolation-type: hyperv
spec:
containers:
- name: iis
image: microsoft/iis
ports:
- containerPort: 80
```
{{< codenew file="windows/deploy-hyperv.yaml" >}}
### Kubelet and kube-proxy can now run as Windows services

View File

@ -1,20 +0,0 @@
apiVersion: v1
kind: Pod
metadata:
name: empty-dir-pod
spec:
containers:
- image: redis:3.0-nanoserver
name: empty-dir-redis
volumeMounts:
- mountPath: /cache
name: cache-volume
- mountPath: C:/scratch
name: scratch-volume
volumes:
- name: cache-volume
emptyDir: {}
- name: scratch-volume
emptyDir: {}
nodeSelector:
beta.kubernetes.io/os: windows

View File

@ -148,7 +148,7 @@ minikube dashboard
The next step is to write the application. Save this code in a folder named `hellonode`
with the filename `server.js`:
{{< code language="js" file="server.js" >}}
{{< codenew language="js" file="minikube/server.js" >}}
Run your application:
@ -168,7 +168,7 @@ Create a file, also in the `hellonode` folder, named `Dockerfile`. A Dockerfile
the image that you want to build. You can build a Docker container image by extending an
existing image. The image in this tutorial extends an existing Node.js image.
{{< code language="conf" file="Dockerfile" >}}
{{< codenew language="conf" file="minikube/Dockerfile" >}}
This recipe for the Docker image starts from the official Node.js LTS image
found in the Docker registry, exposes port 8080, copies your `server.js` file

View File

@ -35,7 +35,7 @@ For more information, see [Pods](/docs/concepts/workloads/pods/pod/).
The simplest Pod definition describes the deployment of a single container. For example, an nginx web server Pod might be defined as:
{{< code file="pod-nginx.yaml" >}}
{{< codenew file="pods/simple-pod.yaml" >}}
A Pod definition is a declaration of a _desired state_. Desired state is a very important concept in the Kubernetes model. Many things present a desired state to the system, and Kubernetes' ensures that the current state matches the desired state. For example, when you create a Pod and declare that the containers in it to be running. If the containers happen not to be running because of a program failure, Kubernetes continues to (re-)create the Pod in order to drive the pod to the desired state. This process continues until you delete the Pod.
@ -44,10 +44,10 @@ For more information, see [Kubernetes Design Documents and Proposals](https://gi
#### Pod Management
Create a Pod containing an nginx server ([pod-nginx.yaml](/docs/tutorials/pod-nginx.yaml)):
Create a Pod containing an nginx server ([simple-pod.yaml](/examples/pods/simple-pod.yaml)):
```shell
$ kubectl create -f docs/tutorials/pod-nginx.yaml
$ kubectl create -f https://k8s.io/examples/pods/simple-pod.yaml
```
List all Pods:
@ -85,27 +85,25 @@ In this example you can create a Redis Pod with a named volume, and a volume mou
1. Define a Volume:
```yaml
volumes:
- name: redis-persistent-storage
emptyDir: {}
```
```yaml
volumes:
- name: redis-storage
emptyDir: {}
```
2. Define a Volume mount within a container definition:
1. Define a Volume mount within a container definition:
```yaml
volumeMounts:
   # name must match the volume name defined in volumes
   - name: redis-persistent-storage
# mount path within the container
mountPath: /data/redis
```
```yaml
volumeMounts:
 # name must match the volume name defined in volumes
 - name: redis-storage
# mount path within the container
mountPath: /data/redis
```
Here is an example of Redis Pod definition with a persistent storage volume ([redis.yaml](/examples/pods/storage/redis.yaml)):
Here is an example of Redis Pod definition with a persistent storage volume ([pod-redis.yaml](/docs/tutorials/pod-redis.yaml)):
{{< code file="pod-redis.yaml" >}}
{{< codenew file="pods/storage/redis.yaml" >}}
Where:

View File

@ -26,29 +26,29 @@ To add a label, add a labels section under metadata in the Pod definition:
```yaml
labels:
app: nginx
env: test
```
For example, here is the nginx Pod definition with labels ([pod-nginx-with-label.yaml](/docs/tutorials/pod-nginx-with-label.yaml)):
For example, here is the nginx Pod definition with labels ([pod-nginx.yaml](/examples/pods/pod-nginx.yaml)):
{{< code file="pod-nginx-with-label.yaml" >}}
{{< codenew file="pods/pod-nginx.yaml" >}}
Create the labeled Pod ([pod-nginx-with-label.yaml](/docs/tutorials/pod-nginx-with-label.yaml)):
Create the labeled Pod:
```shell
kubectl create -f https://k8s.io/docs/tutorials/pod-nginx-with-label.yaml
kubectl create -f https://k8s.io/examples/pods/pod-nginx.yaml
```
List all Pods with the label `app=nginx`:
List all Pods with the label `env=test`:
```shell
kubectl get pods -l app=nginx
kubectl get pods -l env=test
```
Delete the Pod by label:
```shell
kubectl delete pod -l app=nginx
kubectl delete pod -l env=test
```
For more information, see [Labels](/docs/concepts/overview/working-with-objects/labels/).
@ -116,17 +116,17 @@ For more information, such as how to rollback Deployment changes to a previous v
Once you have a replicated set of Pods, you need an abstraction that enables connectivity between the layers of your application. For example, if you have a Deployment managing your backend jobs, you don't want to have to reconfigure your front-ends whenever you re-scale your backends. Likewise, if the Pods in your backends are scheduled (or rescheduled) onto different machines, you can't be required to re-configure your front-ends. In Kubernetes, the service abstraction achieves these goals. A service provides a way to refer to a set of Pods (selected by labels) with a single static IP address. It may also provide load balancing, if supported by the provider.
For example, here is a service that balances across the Pods created in the previous nginx Deployment example ([service.yaml](/docs/tutorials/service.yaml)):
For example, here is a service that balances across the Pods created in the previous nginx Deployment example ([service.yaml](/examples/service/nginx-service.yaml)):
{{< code file="service.yaml" >}}
{{< codenew file="service/nginx-service.yaml" >}}
### Service Management
Create an nginx service ([service.yaml](/docs/tutorials/service.yaml)):
Create an nginx Service:
```shell
kubectl create -f https://k8s.io/docs/tutorials/service.yaml
kubectl create -f https://k8s.io/examples/service/nginx-service.yaml
```
List all services:
@ -221,13 +221,15 @@ In all cases, if the Kubelet discovers a failure the container is restarted.
The container health checks are configured in the `livenessProbe` section of your container config. There you can also specify an `initialDelaySeconds` that is a grace period from when the container is started to when health checks are performed, to enable your container to perform any necessary initialization.
Here is an example config for a Pod with an HTTP health check ([pod-with-http-healthcheck.yaml](/docs/tutorials/pod-with-http-healthcheck.yaml)):
Here is an example config for a Pod with an HTTP health check
([pod-with-http-healthcheck.yaml](/examples/pods/probe/pod-with-http-healthcheck.yaml)):
{{< code file="pod-with-http-healthcheck.yaml" >}}
{{< codenew file="pods/probe/pod-with-http-healthcheck.yaml" >}}
And here is an example config for a Pod with a TCP Socket health check ([pod-with-tcp-socket-healthcheck.yaml](/docs/tutorials/pod-with-tcp-socket-healthcheck.yaml)):
And here is an example config for a Pod with a TCP Socket health check
([pod-with-tcp-socket-healthcheck.yaml](/examples/pods/probe/pod-with-tcp-socket-healthcheck.yaml)):
{{< code file="pod-with-tcp-socket-healthcheck.yaml" >}}
{{< codenew file="pods/probe/pod-with-tcp-socket-healthcheck.yaml" >}}
For more information about health checking, see [Container Probes](/docs/user-guide/pod-states/#container-probes).

View File

@ -1,12 +0,0 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

View File

@ -1,14 +0,0 @@
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis
volumeMounts:
- name: redis-persistent-storage
mountPath: /data/redis
volumes:
- name: redis-persistent-storage
emptyDir: {}

View File

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: my-daemonset
labels:
app: foo
spec:
selector:
matchLabels:
app: foo
template:
metadata:
labels:
app: foo
spec:
containers:
- name: foo
image: microsoft/windowsservercore:1709
nodeSelector:
beta.kubernetes.io/os: windows

View File

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: iis
spec:
selector:
matchLabels:
app: iis
replicas: 3
template:
metadata:
labels:
app: iis
annotations:
experimental.windows.kubernetes.io/isolation-type: hyperv
spec:
containers:
- name: iis
image: microsoft/iis
ports:
- containerPort: 80

View File

@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: iis
spec:
replicas: 3
selector:
matchLabels:
app: iis
template:
metadata:
labels:
app: iis
spec:
containers:
- name: iis
image: microsoft/iis
resources:
limits:
memory: "128Mi"
cpu: 2
ports:
- containerPort: 80

View File

@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
name: my-empty-dir-pod
spec:
containers:
- image: microsoft/windowsservercore:1709
name: my-empty-dir-pod
volumeMounts:
- mountPath: /cache
name: cache-volume
- mountPath: C:/scratch
name: scratch-volume
volumes:
- name: cache-volume
emptyDir: {}
- name: scratch-volume
emptyDir: {}
nodeSelector:
beta.kubernetes.io/os: windows

View File

@ -4,15 +4,15 @@ metadata:
name: hostpath-volume-pod
spec:
containers:
- name: hostpath-redis
image: redis:3.0-nanoserver
- name: my-hostpath-volume-pod
image: microsoft/windowsservercore:1709
volumeMounts:
- name: blah
- name: foo
mountPath: "C:\\etc\\foo"
readOnly: true
nodeSelector:
beta.kubernetes.io/os: windows
volumes:
- name: blah
- name: foo
hostPath:
path: "C:\\etc\\foo"
path: "C:\\etc\\foo"

View File

@ -12,11 +12,11 @@ data:
apiVersion: v1
kind: Pod
metadata:
name: mypod-secret
name: my-secret-pod
spec:
containers:
- name: mypod-secret
image: redis:3.0-nanoserver
- name: my-secret-pod
image: microsoft/windowsservercore:1709
env:
- name: USERNAME
valueFrom:
@ -29,4 +29,4 @@ spec:
name: mysecret
key: password
nodeSelector:
beta.kubernetes.io/os: windows
beta.kubernetes.io/os: windows

View File

@ -0,0 +1,14 @@
apiVersion: v1
kind: Pod
metadata:
name: iis
labels:
name: iis
spec:
containers:
- name: iis
image: microsoft/iis:windowsservercore-1709
ports:
- containerPort: 80
nodeSelector:
"beta.kubernetes.io/os": windows

View File

@ -468,6 +468,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"pod-with-pod-affinity": {&api.Pod{}},
"private-reg-pod": {&api.Pod{}},
"share-process-namespace": {&api.Pod{}},
"simple-pod": {&api.Pod{}},
"two-container-pod": {&api.Pod{}},
},
"examples/pods/inject": {
@ -483,6 +484,8 @@ func TestExampleObjectSchemas(t *testing.T) {
"examples/pods/probe": {
"exec-liveness": {&api.Pod{}},
"http-liveness": {&api.Pod{}},
"pod-with-http-healthcheck": {&api.Pod{}},
"pod-with-tcp-socket-healthcheck": {&api.Pod{}},
"tcp-liveness-readiness": {&api.Pod{}},
},
"examples/pods/qos": {
@ -518,11 +521,24 @@ func TestExampleObjectSchemas(t *testing.T) {
"restricted-psp": {&policy.PodSecurityPolicy{}},
"example-psp": {&policy.PodSecurityPolicy{}},
},
"examples/service": {
"nginx-service": {&api.Service{}},
},
"examples/service/access": {
"frontend": {&api.Service{}, &extensions.Deployment{}},
"hello-service": {&api.Service{}},
"hello": {&extensions.Deployment{}},
},
"examples/windows": {
"configmap-pod": {&api.ConfigMap{}, &api.Pod{}},
"daemonset": {&extensions.DaemonSet{}},
"deploy-hyperv": {&extensions.Deployment{}},
"deploy-resource": {&extensions.Deployment{}},
"emptydir-pod": {&api.Pod{}},
"hostpath-volume-pod": {&api.Pod{}},
"secret-pod": {&api.Secret{}, &api.Pod{}},
"simple-pod": {&api.Pod{}},
},
}
// Note a key in the following map has to be complete relative path