mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #7649 from brendandburns/example
Add a central simple getting started guide with kubernetes guide.
This commit is contained in:
		@@ -57,7 +57,6 @@ then ```foo-next``` is synthesized using the pattern ```<controller-name>-<hash-
 | 
				
			|||||||
#### Initialization
 | 
					#### Initialization
 | 
				
			||||||
   * If ```foo``` and ```foo-next``` do not exist:
 | 
					   * If ```foo``` and ```foo-next``` do not exist:
 | 
				
			||||||
      * Exit, and indicate an error to the user, that the specified controller doesn't exist.
 | 
					      * Exit, and indicate an error to the user, that the specified controller doesn't exist.
 | 
				
			||||||
      * Goto Rollout
 | 
					 | 
				
			||||||
   * If ```foo``` exists, but ```foo-next``` does not:
 | 
					   * If ```foo``` exists, but ```foo-next``` does not:
 | 
				
			||||||
      * Create ```foo-next``` populate it with the ```v2``` image, set ```desired-replicas``` to ```foo.Spec.Replicas```
 | 
					      * Create ```foo-next``` populate it with the ```v2``` image, set ```desired-replicas``` to ```foo.Spec.Replicas```
 | 
				
			||||||
      * Goto Rollout
 | 
					      * Goto Rollout
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,97 +32,21 @@ Once the cluster is up, it will print the ip address of your cluster, this proce
 | 
				
			|||||||
export KUBERNETES_MASTER=https://<ip-address>
 | 
					export KUBERNETES_MASTER=https://<ip-address>
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Also setup your path to point to the released binaries:
 | 
					Copy the appropriate ```kubectl``` binary to somewhere in your ```PATH```, for example:
 | 
				
			||||||
```
 | 
					 | 
				
			||||||
export PATH=$PATH:$PWD:/kubernetes/cluster
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
If you run into trouble come ask questions on IRC at #google-containers on freenode.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Running a container (simple version)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Once you have your cluster created you can use ```${SOME_DIR}/kubernetes/cluster/kubectl.sh``` to access
 | 
					 | 
				
			||||||
the kubernetes api.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The `kubectl.sh` line below spins up two containers running
 | 
					 | 
				
			||||||
[Nginx](http://nginx.org/en/) running on port 80:
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
cluster/kubectl.sh run-container my-nginx --image=nginx --replicas=2 --port=80
 | 
					# OS X
 | 
				
			||||||
 | 
					sudo cp kubernetes/platforms/darwin/amd64/kubectl /usr/local/bin/kubectl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Linux
 | 
				
			||||||
 | 
					sudo cp kubernetes/platforms/linux/amd64/kubectl /usr/local/bin/kubectl
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To stop the containers:
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					### Getting started with your cluster
 | 
				
			||||||
cluster/kubectl.sh stop rc my-nginx
 | 
					See [a simple nginx example](../../examples/simple-nginx.md) to try out your new cluster.
 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
To delete the containers:
 | 
					For more complete applications, please look in the [examples directory](../../examples)
 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh delete rc my-nginx
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Running a container (more complete version)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cd kubernetes
 | 
					 | 
				
			||||||
cluster/kubectl.sh create -f docs/getting-started-guides/pod.json
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Where pod.json contains something like:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```json
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  "id": "php",
 | 
					 | 
				
			||||||
  "kind": "Pod",
 | 
					 | 
				
			||||||
  "apiVersion": "v1beta1",
 | 
					 | 
				
			||||||
  "desiredState": {
 | 
					 | 
				
			||||||
    "manifest": {
 | 
					 | 
				
			||||||
      "version": "v1beta1",
 | 
					 | 
				
			||||||
      "id": "php",
 | 
					 | 
				
			||||||
      "containers": [{
 | 
					 | 
				
			||||||
        "name": "nginx",
 | 
					 | 
				
			||||||
        "image": "nginx",
 | 
					 | 
				
			||||||
        "ports": [{
 | 
					 | 
				
			||||||
          "containerPort": 80,
 | 
					 | 
				
			||||||
          "hostPort": 8081
 | 
					 | 
				
			||||||
        }],
 | 
					 | 
				
			||||||
        "livenessProbe": {
 | 
					 | 
				
			||||||
          "enabled": true,
 | 
					 | 
				
			||||||
          "type": "http",
 | 
					 | 
				
			||||||
          "initialDelaySeconds": 30,
 | 
					 | 
				
			||||||
          "httpGet": {
 | 
					 | 
				
			||||||
            "path": "/index.html",
 | 
					 | 
				
			||||||
            "port": 8081
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }]
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  "labels": {
 | 
					 | 
				
			||||||
    "name": "foo"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
You can see your cluster's pods:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh get pods
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
and delete the pod you just created:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh delete pods php
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Since this pod is scheduled on a minion running in AWS, you will have to enable incoming tcp traffic via the port specified in the
 | 
					 | 
				
			||||||
pod manifest before you see the nginx welcome page. After doing so, it should be visible at http://<external ip of minion running nginx>:<port from manifest>.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Look in `examples/` for more examples
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Tearing down the cluster
 | 
					### Tearing down the cluster
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,3 +41,5 @@ See [here](docker-multinode/worker.md) for detailed instructions.
 | 
				
			|||||||
## Testing your cluster
 | 
					## Testing your cluster
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Once your cluster has been created you can [test it out](docker-multinode/testing.md)
 | 
					Once your cluster has been created you can [test it out](docker-multinode/testing.md)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For more complete applications, please look in the [examples directory](../../examples)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,99 +33,24 @@ wget -q -O - https://get.k8s.io | bash
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
This will leave you with a ```kubernetes``` directory on your workstation, and a running cluster.
 | 
					This will leave you with a ```kubernetes``` directory on your workstation, and a running cluster.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Feel free to move the ```kubernetes``` directory to the appropriate directory on your workstation (e.g. ```/opt/kubernetes```) then ```cd``` into that directory:
 | 
					Copy the appropriate ```kubectl``` binary to somewhere in your ```PATH```, for example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
mv kubernetes ${SOME_DIR}/kubernetes
 | 
					# OS X
 | 
				
			||||||
cd ${SOME_DIR}/kubernetes
 | 
					sudo cp kubernetes/platforms/darwin/amd64/kubectl /usr/local/bin/kubectl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Linux
 | 
				
			||||||
 | 
					sudo cp kubernetes/platforms/linux/amd64/kubectl /usr/local/bin/kubectl
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
If you run into trouble please see the section on [troubleshooting](https://github.com/brendandburns/kubernetes/blob/docs/docs/getting-started-guides/gce.md#troubleshooting), or come ask questions on IRC at #google-containers on freenode.
 | 
					If you run into trouble please see the section on [troubleshooting](https://github.com/brendandburns/kubernetes/blob/docs/docs/getting-started-guides/gce.md#troubleshooting), or come ask questions on IRC at #google-containers on freenode.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Running a container (simple version)
 | 
					### Getting started with your cluster
 | 
				
			||||||
 | 
					See [a simple nginx example](../../examples/simple-nginx.md) to try out your new cluster.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Once you have your cluster created you can use ```${SOME_DIR}/kubernetes/cluster/kubectl.sh``` to access
 | 
					For more complete applications, please look in the [examples directory](../../examples)
 | 
				
			||||||
the kubernetes api.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
The `kubectl.sh` line below spins up two containers running
 | 
					 | 
				
			||||||
[Nginx](http://nginx.org/en/) running on port 80:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh run-container my-nginx --image=nginx --replicas=2 --port=80
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
To stop the containers:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh stop rc my-nginx
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
To delete the containers:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh delete rc my-nginx
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Running a container (more complete version)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cd kubernetes
 | 
					 | 
				
			||||||
cluster/kubectl.sh create -f docs/getting-started-guides/pod.json
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Where pod.json contains something like:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```json
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  "id": "php",
 | 
					 | 
				
			||||||
  "kind": "Pod",
 | 
					 | 
				
			||||||
  "apiVersion": "v1beta1",
 | 
					 | 
				
			||||||
  "desiredState": {
 | 
					 | 
				
			||||||
    "manifest": {
 | 
					 | 
				
			||||||
      "version": "v1beta1",
 | 
					 | 
				
			||||||
      "id": "php",
 | 
					 | 
				
			||||||
      "containers": [{
 | 
					 | 
				
			||||||
        "name": "nginx",
 | 
					 | 
				
			||||||
        "image": "nginx",
 | 
					 | 
				
			||||||
        "ports": [{
 | 
					 | 
				
			||||||
          "containerPort": 80,
 | 
					 | 
				
			||||||
          "hostPort": 8081
 | 
					 | 
				
			||||||
        }],
 | 
					 | 
				
			||||||
        "livenessProbe": {
 | 
					 | 
				
			||||||
          "enabled": true,
 | 
					 | 
				
			||||||
          "type": "http",
 | 
					 | 
				
			||||||
          "initialDelaySeconds": 30,
 | 
					 | 
				
			||||||
          "httpGet": {
 | 
					 | 
				
			||||||
            "path": "/index.html",
 | 
					 | 
				
			||||||
            "port": 8081
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }]
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  "labels": {
 | 
					 | 
				
			||||||
    "name": "foo"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
You can see your cluster's pods:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh get pods
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
and delete the pod you just created:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
cluster/kubectl.sh delete pods php
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Since this pod is scheduled on a minion running in GCE, you will have to enable incoming tcp traffic via the port specified in the
 | 
					 | 
				
			||||||
pod manifest before you see the nginx welcome page. After doing so, it should be visible at http://<external ip of minion running nginx>:<port from manifest>.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Look in `examples/` for more examples
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Tearing down the cluster
 | 
					### Tearing down the cluster
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,32 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
  "kind": "Pod",
 | 
					 | 
				
			||||||
  "apiVersion": "v1beta1",
 | 
					 | 
				
			||||||
  "id": "php",
 | 
					 | 
				
			||||||
  "desiredState": {
 | 
					 | 
				
			||||||
    "manifest": {
 | 
					 | 
				
			||||||
      "version": "v1beta1",
 | 
					 | 
				
			||||||
      "id": "php",
 | 
					 | 
				
			||||||
      "containers": [{
 | 
					 | 
				
			||||||
        "name": "nginx",
 | 
					 | 
				
			||||||
        "image": "nginx",
 | 
					 | 
				
			||||||
        "ports": [{
 | 
					 | 
				
			||||||
          "containerPort": 80,
 | 
					 | 
				
			||||||
          "hostPort": 8081
 | 
					 | 
				
			||||||
        }],
 | 
					 | 
				
			||||||
        "livenessProbe": {
 | 
					 | 
				
			||||||
          "enabled": true,
 | 
					 | 
				
			||||||
          "type": "http",
 | 
					 | 
				
			||||||
          "initialDelaySeconds": 30,
 | 
					 | 
				
			||||||
          "httpGet": {
 | 
					 | 
				
			||||||
            "path": "/",
 | 
					 | 
				
			||||||
            "port": "80"
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }]
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  "labels": {
 | 
					 | 
				
			||||||
    "name": "foo"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@@ -115,9 +115,6 @@ func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestExampleObjectSchemas(t *testing.T) {
 | 
					func TestExampleObjectSchemas(t *testing.T) {
 | 
				
			||||||
	cases := map[string]map[string]runtime.Object{
 | 
						cases := map[string]map[string]runtime.Object{
 | 
				
			||||||
		"../docs/getting-started-guides": {
 | 
					 | 
				
			||||||
			"pod": &api.Pod{},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		"../cmd/integration": {
 | 
							"../cmd/integration": {
 | 
				
			||||||
			"v1beta1-controller": &api.ReplicationController{},
 | 
								"v1beta1-controller": &api.ReplicationController{},
 | 
				
			||||||
			"v1beta3-controller": &api.ReplicationController{},
 | 
								"v1beta3-controller": &api.ReplicationController{},
 | 
				
			||||||
@@ -177,6 +174,10 @@ func TestExampleObjectSchemas(t *testing.T) {
 | 
				
			|||||||
		"../examples/glusterfs/v1beta3": {
 | 
							"../examples/glusterfs/v1beta3": {
 | 
				
			||||||
			"glusterfs": &api.Pod{},
 | 
								"glusterfs": &api.Pod{},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							"../examples": {
 | 
				
			||||||
 | 
								"pod":         &api.Pod{},
 | 
				
			||||||
 | 
								"replication": &api.ReplicationController{},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for path, expected := range cases {
 | 
						for path, expected := range cases {
 | 
				
			||||||
@@ -225,14 +226,18 @@ var sampleRegexp = regexp.MustCompile("(?ms)^```(?:(?P<type>yaml)\\w*\\n(?P<cont
 | 
				
			|||||||
var subsetRegexp = regexp.MustCompile("(?ms)\\.{3}")
 | 
					var subsetRegexp = regexp.MustCompile("(?ms)\\.{3}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestReadme(t *testing.T) {
 | 
					func TestReadme(t *testing.T) {
 | 
				
			||||||
	paths := []string{
 | 
						paths := []struct {
 | 
				
			||||||
		"../README.md",
 | 
							file         string
 | 
				
			||||||
		"../examples/walkthrough/README.md",
 | 
							expectedType []runtime.Object
 | 
				
			||||||
		"../examples/iscsi/README.md",
 | 
						}{
 | 
				
			||||||
 | 
							{"../README.md", []runtime.Object{&api.Pod{}}},
 | 
				
			||||||
 | 
							{"../examples/walkthrough/README.md", []runtime.Object{&api.Pod{}}},
 | 
				
			||||||
 | 
							{"../examples/iscsi/README.md", []runtime.Object{&api.Pod{}}},
 | 
				
			||||||
 | 
							{"../examples/simple-yaml.md", []runtime.Object{&api.Pod{}, &api.ReplicationController{}}},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, path := range paths {
 | 
						for _, path := range paths {
 | 
				
			||||||
		data, err := ioutil.ReadFile(path)
 | 
							data, err := ioutil.ReadFile(path.file)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			t.Errorf("Unable to read file %s: %v", path, err)
 | 
								t.Errorf("Unable to read file %s: %v", path, err)
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
@@ -242,6 +247,7 @@ func TestReadme(t *testing.T) {
 | 
				
			|||||||
		if matches == nil {
 | 
							if matches == nil {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							ix := 0
 | 
				
			||||||
		for _, match := range matches {
 | 
							for _, match := range matches {
 | 
				
			||||||
			var content, subtype string
 | 
								var content, subtype string
 | 
				
			||||||
			for i, name := range sampleRegexp.SubexpNames() {
 | 
								for i, name := range sampleRegexp.SubexpNames() {
 | 
				
			||||||
@@ -257,8 +263,13 @@ func TestReadme(t *testing.T) {
 | 
				
			|||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//t.Logf("testing (%s): \n%s", subtype, content)
 | 
								var expectedType runtime.Object
 | 
				
			||||||
			expectedType := &api.Pod{}
 | 
								if len(path.expectedType) == 1 {
 | 
				
			||||||
 | 
									expectedType = path.expectedType[0]
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									expectedType = path.expectedType[ix]
 | 
				
			||||||
 | 
									ix++
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			json, err := yaml.ToJSON([]byte(content))
 | 
								json, err := yaml.ToJSON([]byte(content))
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				t.Errorf("%s could not be converted to JSON: %v\n%s", path, err, string(content))
 | 
									t.Errorf("%s could not be converted to JSON: %v\n%s", path, err, string(content))
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								examples/pod.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								examples/pod.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					apiVersion: v1beta3
 | 
				
			||||||
 | 
					kind: Pod
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    name: nginx
 | 
				
			||||||
 | 
					  name: nginx
 | 
				
			||||||
 | 
					  namespace: default
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  containers:
 | 
				
			||||||
 | 
					  - image: nginx
 | 
				
			||||||
 | 
					    imagePullPolicy: IfNotPresent
 | 
				
			||||||
 | 
					    name: nginx
 | 
				
			||||||
 | 
					    ports:
 | 
				
			||||||
 | 
					    - containerPort: 80
 | 
				
			||||||
 | 
					      protocol: TCP
 | 
				
			||||||
 | 
					  restartPolicy: Always
 | 
				
			||||||
							
								
								
									
										23
									
								
								examples/replication.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								examples/replication.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					apiVersion: v1beta3
 | 
				
			||||||
 | 
					kind: ReplicationController
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: nginx
 | 
				
			||||||
 | 
					  namespace: default
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  replicas: 3
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    app: nginx
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    metadata:
 | 
				
			||||||
 | 
					      name: nginx
 | 
				
			||||||
 | 
					      labels:
 | 
				
			||||||
 | 
					        app: nginx
 | 
				
			||||||
 | 
					    spec:
 | 
				
			||||||
 | 
					      containers:
 | 
				
			||||||
 | 
					      - image: nginx
 | 
				
			||||||
 | 
					        imagePullPolicy: IfNotPresent
 | 
				
			||||||
 | 
					        name: nginx
 | 
				
			||||||
 | 
					        ports:
 | 
				
			||||||
 | 
					        - containerPort: 80
 | 
				
			||||||
 | 
					          protocol: TCP
 | 
				
			||||||
 | 
					      restartPolicy: Always
 | 
				
			||||||
							
								
								
									
										44
									
								
								examples/simple-nginx.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								examples/simple-nginx.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					## Running your first containers in Kubernetes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Ok, you've run one of the [getting started guides](../docs/getting-started-guides/) and you have
 | 
				
			||||||
 | 
					successfully turned up a Kubernetes cluster.  Now what?  This guide will help you get oriented
 | 
				
			||||||
 | 
					to Kubernetes and running your first containers on the cluster.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Running a container (simple version)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Assume that ```${KUBERNETES_HOME}``` points to the directory where you installed the kubernetes directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Once you have your cluster created you can use ```${KUBERNETES_HOME/kubernetes/cluster/kubectl.sh``` to access
 | 
				
			||||||
 | 
					the kubernetes api.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The `kubectl.sh` line below spins up two containers running
 | 
				
			||||||
 | 
					[Nginx](http://nginx.org/en/) running on port 80:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					kubectl run-container my-nginx --image=nginx --replicas=2 --port=80
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Once the pods are created, you can list them to see what is up and running:
 | 
				
			||||||
 | 
					```base
 | 
				
			||||||
 | 
					kubectl get pods
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To stop the two replicated containers:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					kubectl stop rc my-nginx
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Exposing your pods to the internet.
 | 
				
			||||||
 | 
					On some platforms (for example Google Compute Engine) the kubectl command can integrate with your cloud provider to add a public IP address for the pods,
 | 
				
			||||||
 | 
					to do this run:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					kubectl expose rc nginx --port=80 --create-external-load-balancer
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This should print the service that has been created, and map an external IP address to the service.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Next: Configuration files
 | 
				
			||||||
 | 
					Most people will eventually want to use declarative configuration files for creating/modifying their applications.  A [simplified introduction](simple-yaml.md)
 | 
				
			||||||
 | 
					is given in a different document.
 | 
				
			||||||
							
								
								
									
										89
									
								
								examples/simple-yaml.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								examples/simple-yaml.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
				
			|||||||
 | 
					## Getting started with config files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					In addition to the imperative style commands described [elsewhere](simple-nginx.md), Kubernetes
 | 
				
			||||||
 | 
					supports declarative YAML or JSON configuration files.  Often times config files are prefereable
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					kubectl create -f pod.yaml
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Where pod.yaml contains something like:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
 | 
					apiVersion: v1beta3
 | 
				
			||||||
 | 
					kind: Pod
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    app: nginx
 | 
				
			||||||
 | 
					  name: nginx
 | 
				
			||||||
 | 
					  namespace: default
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  containers:
 | 
				
			||||||
 | 
					  - image: nginx
 | 
				
			||||||
 | 
					    imagePullPolicy: IfNotPresent
 | 
				
			||||||
 | 
					    name: nginx
 | 
				
			||||||
 | 
					    ports:
 | 
				
			||||||
 | 
					    - containerPort: 80
 | 
				
			||||||
 | 
					      protocol: TCP
 | 
				
			||||||
 | 
					  restartPolicy: Always
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					To run replicated containers, you need a [Replication Controller](../docs/replication-controller.md).
 | 
				
			||||||
 | 
					A replication controller is responsible for ensuring that a specific number of pods exist in the
 | 
				
			||||||
 | 
					cluster.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					cd kubernetes
 | 
				
			||||||
 | 
					kubectl create -f replication.yaml
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Where ```replication.yaml``` contains:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
 | 
					apiVersion: v1beta3
 | 
				
			||||||
 | 
					kind: ReplicationController
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: nginx
 | 
				
			||||||
 | 
					  namespace: default
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  replicas: 3
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    app: nginx
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    metadata:
 | 
				
			||||||
 | 
					      name: nginx
 | 
				
			||||||
 | 
					      labels:
 | 
				
			||||||
 | 
					        app: nginx
 | 
				
			||||||
 | 
					    spec:
 | 
				
			||||||
 | 
					      containers:
 | 
				
			||||||
 | 
					      - image: nginx
 | 
				
			||||||
 | 
					        imagePullPolicy: IfNotPresent
 | 
				
			||||||
 | 
					        name: nginx
 | 
				
			||||||
 | 
					        ports:
 | 
				
			||||||
 | 
					        - containerPort: 80
 | 
				
			||||||
 | 
					          protocol: TCP
 | 
				
			||||||
 | 
					      restartPolicy: Always
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To delete the replication controller (and the pods it created):
 | 
				
			||||||
 | 
					```bash
 | 
				
			||||||
 | 
					kubectl delete rc nginx
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
		Reference in New Issue
	
	Block a user