2015-07-14 00:13:09 +00:00
|
|
|
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
|
|
|
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
|
|
|
|
2015-07-16 17:02:26 +00:00
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
|
|
|
width="25" height="25">
|
|
|
|
|
|
|
|
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
|
|
|
|
|
|
|
|
If you are using a released version of Kubernetes, you should
|
|
|
|
refer to the docs that go with that version.
|
|
|
|
|
|
|
|
<strong>
|
|
|
|
The latest 1.0.x release of this document can be found
|
|
|
|
[here](http://releases.k8s.io/release-1.0/docs/user-guide/simple-yaml.md).
|
|
|
|
|
|
|
|
Documentation for other releases can be found at
|
|
|
|
[releases.k8s.io](http://releases.k8s.io).
|
|
|
|
</strong>
|
|
|
|
--
|
2015-07-13 22:15:35 +00:00
|
|
|
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- END STRIP_FOR_RELEASE -->
|
|
|
|
|
|
|
|
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
2015-05-01 05:16:59 +00:00
|
|
|
## Getting started with config files.
|
|
|
|
|
|
|
|
In addition to the imperative style commands described [elsewhere](simple-nginx.md), Kubernetes
|
2015-05-27 00:26:47 +00:00
|
|
|
supports declarative YAML or JSON configuration files. Often times config files are preferable
|
2015-05-01 05:16:59 +00:00
|
|
|
to imperative commands, since they can be checked into version control and changes to the files
|
|
|
|
can be code reviewed, producing a more robust, reliable and archival system.
|
|
|
|
|
|
|
|
### Running a container from a pod configuration file
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd kubernetes
|
2015-07-16 00:20:39 +00:00
|
|
|
kubectl create -f ./pod.yaml
|
2015-05-01 05:16:59 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Where pod.yaml contains something like:
|
|
|
|
|
|
|
|
```yaml
|
2015-06-10 23:31:47 +00:00
|
|
|
apiVersion: v1
|
2015-05-01 05:16:59 +00:00
|
|
|
kind: Pod
|
|
|
|
metadata:
|
2015-06-10 23:31:47 +00:00
|
|
|
name: nginx
|
2015-05-01 05:16:59 +00:00
|
|
|
labels:
|
|
|
|
app: nginx
|
|
|
|
spec:
|
|
|
|
containers:
|
2015-06-10 23:31:47 +00:00
|
|
|
- name: nginx
|
|
|
|
image: nginx
|
2015-05-01 05:16:59 +00:00
|
|
|
ports:
|
|
|
|
- containerPort: 80
|
|
|
|
```
|
|
|
|
|
|
|
|
You can see your cluster's pods:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
kubectl get pods
|
|
|
|
```
|
|
|
|
|
|
|
|
and delete the pod you just created:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
kubectl delete pods nginx
|
|
|
|
```
|
|
|
|
|
|
|
|
### Running a replicated set of containers from a configuration file
|
2015-07-14 16:37:37 +00:00
|
|
|
To run replicated containers, you need a [Replication Controller](replication-controller.md).
|
2015-05-01 05:16:59 +00:00
|
|
|
A replication controller is responsible for ensuring that a specific number of pods exist in the
|
|
|
|
cluster.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd kubernetes
|
2015-07-16 00:20:39 +00:00
|
|
|
kubectl create -f ./replication.yaml
|
2015-05-01 05:16:59 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Where ```replication.yaml``` contains:
|
|
|
|
|
|
|
|
```yaml
|
2015-06-10 23:31:47 +00:00
|
|
|
apiVersion: v1
|
2015-05-01 05:16:59 +00:00
|
|
|
kind: ReplicationController
|
|
|
|
metadata:
|
|
|
|
name: nginx
|
|
|
|
spec:
|
|
|
|
replicas: 3
|
|
|
|
selector:
|
|
|
|
app: nginx
|
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
name: nginx
|
|
|
|
labels:
|
|
|
|
app: nginx
|
|
|
|
spec:
|
|
|
|
containers:
|
2015-06-10 23:31:47 +00:00
|
|
|
- name: nginx
|
|
|
|
image: nginx
|
2015-05-01 05:16:59 +00:00
|
|
|
ports:
|
|
|
|
- containerPort: 80
|
|
|
|
```
|
|
|
|
|
|
|
|
To delete the replication controller (and the pods it created):
|
2015-07-17 02:01:02 +00:00
|
|
|
|
2015-05-01 05:16:59 +00:00
|
|
|
```bash
|
|
|
|
kubectl delete rc nginx
|
|
|
|
```
|
2015-05-14 22:12:45 +00:00
|
|
|
|
|
|
|
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
2015-07-14 16:37:37 +00:00
|
|
|
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/simple-yaml.md?pixel)]()
|
2015-07-14 00:13:09 +00:00
|
|
|
<!-- END MUNGE: GENERATED_ANALYTICS -->
|