|
10 | 10 |
|
11 | 11 | toc::[]
|
12 | 12 |
|
13 |
| -== Deployments |
14 |
| -See link:../../dev_guide/deployments.html[Deployments]. |
| 13 | +== Replication Controllers |
15 | 14 |
|
16 |
| -== Deployment Configurations |
17 |
| -See link:../../dev_guide/deployments.html[Deployments]. |
| 15 | +A replication controller ensures that a specified number of replicas of a pod |
| 16 | +are running at all times. If pods exit or are deleted, the replica controller |
| 17 | +acts to instantiate more up to the desired number. Likewise, if there are more |
| 18 | +running than desired, it deletes as many as necessary to match the number. |
18 | 19 |
|
19 |
| -== Replication Controllers |
| 20 | +The definition of a replication controller consists mainly of: |
| 21 | + |
| 22 | +1. The number of replicas desired (which can be adjusted at runtime). |
| 23 | +2. A pod definition for creating a replicated pod. |
| 24 | +3. A selector for identifying managed pods. |
20 | 25 |
|
21 |
| -A replication controller ensures that a specific number of pods set with a |
22 |
| -particular label are running at all times. If one of the matching pods or a |
23 |
| -Kubernetes host goes down, the replication controller re-instantiates matching |
24 |
| -pods up to the defined number across the cluster. Likewise, if there are too |
25 |
| -many running pods, it kills the required amount of hosts. Any new pods are |
26 |
| -created by the template set in the replication controller object. |
| 26 | +The selector is just a set of labels that all of the pods managed by the |
| 27 | +replication controller should have. So that set of labels is included |
| 28 | +in the pod definition that the replication controller instantiates. |
| 29 | +This selector is used by the replication controller to determine how many |
| 30 | +instances of the pod are already running in order to adjust as needed. |
27 | 31 |
|
28 |
| -The replication controller does not perform auto-scaling; rather, it is |
29 |
| -controlled by an external auto-scaler, which changes the `*replicas*` field. |
30 |
| -Replication controllers are only appropriate for pods with `*restartPolicy*` set |
31 |
| -to *Always*, and a pod with a different restart policy is refused. |
| 32 | +It is not the job of the replication controller to perform auto-scaling |
| 33 | +based on load or traffic, as it does not track either; rather, this |
| 34 | +would require its replica count to be adjusted by an external auto-scaler. |
32 | 35 |
|
33 |
| -The most important elements in the structure of a replication controller object |
34 |
| -are the `*replicas*` and `*replicaSelector*` values, as shown in the following |
35 |
| -example: |
| 36 | +Replication controllers are a core Kubernetes object, `*ReplicationController*`. See the |
| 37 | +https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/replication-controller.md[Kubernetes |
| 38 | +documentation] for more on replication controllers. |
36 | 39 |
|
37 |
| -.Replication Controller Object Definition |
38 |
| -==== |
| 40 | +Here is an example `*ReplicationController*` definition with some omissions and callouts: |
39 | 41 |
|
40 |
| -[source,json] |
| 42 | +[source,yaml] |
41 | 43 | ----
|
42 |
| -{ |
43 |
| - "kind": "ReplicationControllerList", |
44 |
| - "creationTimestamp": null, |
45 |
| - "selfLink": "/api/v1beta1/replicationControllers", |
46 |
| - "resourceVersion": 27, |
47 |
| - "apiVersion": "v1beta1", |
48 |
| - "items": [ |
49 |
| - { |
50 |
| - "id": "docker-registry-1", |
51 |
| - "uid": "7fa58610-9b31-11e4-9dff-f0def1de880f", |
52 |
| - "creationTimestamp": "2015-01-13T09:36:02-05:00", |
53 |
| - "selfLink": "/api/v1beta1/replicationControllers/docker-registry-1?namespace=default", |
54 |
| - "resourceVersion": 26, |
55 |
| - "namespace": "default", |
56 |
| - "annotations": { |
57 |
| - ... |
58 |
| - }, |
59 |
| - "desiredState": { |
60 |
| - "replicas": 1, <1> |
61 |
| - "replicaSelector": { |
62 |
| - "name": "registrypod" <2> |
63 |
| - }, |
| 44 | +apiVersion: v1 |
| 45 | +kind: ReplicationController |
| 46 | +metadata: |
| 47 | + name: frontend-1 |
| 48 | +spec: |
| 49 | + replicas: 1 <1> |
| 50 | + selector: <2> |
| 51 | + name: frontend |
| 52 | + template: <3> |
| 53 | + metadata: |
| 54 | + labels: <4> |
| 55 | + name: frontend |
| 56 | + spec: |
| 57 | + containers: |
| 58 | + - image: openshift/hello-openshift |
| 59 | + name: helloworld |
| 60 | + ports: |
| 61 | + - containerPort: 8080 |
| 62 | + protocol: TCP |
| 63 | + restartPolicy: Always |
64 | 64 | ----
|
65 |
| -<1> The number of copies of the pod to run. |
66 |
| -<2> The label selector of the pod to run. |
67 | 65 |
|
68 |
| -==== |
| 66 | +1. The number of copies of the pod to run. |
| 67 | +2. The label selector of the pod to run. |
| 68 | +3. A template for the pod the controller creates. |
| 69 | +4. Labels on the pod should include those from the label selector. |
69 | 70 |
|
70 |
| -These determine which pods to maintain. |
| 71 | +== Deployments and Deployment Configurations |
| 72 | + |
| 73 | +Building on replication controllers, OpenShift adds expanded support |
| 74 | +for the software development and deployment lifecycle with the concept |
| 75 | +of deployments. In the simplest case, a deployment just creates a new |
| 76 | +replication controller and lets it start up pods. However, OpenShift |
| 77 | +deployments also provide the ability to transition from an existing |
| 78 | +deployment of an image to a new one and also define hooks to be run |
| 79 | +before or after creating the replication controller. |
| 80 | + |
| 81 | +The OpenShift DeploymentConfiguration object defines the following details of a deployment: |
| 82 | + |
| 83 | +1. The elements of a `*ReplicationController*` definition. |
| 84 | +2. Triggers for creating a new deployment automatically. |
| 85 | +3. The strategy for transitioning between deployments. |
| 86 | +4. Life cycle hooks. |
| 87 | + |
| 88 | +Each time a deployment is triggered, whether manually or automatically, |
| 89 | +a deployer pod manages the deployment (including scaling down the old |
| 90 | +replication controller, scaling up the new one, and running hooks). |
| 91 | +The deployment pod remains for an indefinite amount of time after it |
| 92 | +completes the deployment in order to retain its logs of the deployment. |
| 93 | +When a deployment is superseded by another, the previous replication |
| 94 | +controller is retained to enable easy rollback if needed. |
| 95 | + |
| 96 | +For detailed instructions on how to create and interact with deployments, |
| 97 | +refer to link:../../dev_guide/deployments.html[Deployments]. |
| 98 | + |
| 99 | +Here is an example `*DeploymentConfiguration*` definition with some |
| 100 | +omissions and callouts: |
| 101 | + |
| 102 | +[source,yaml] |
| 103 | +---- |
| 104 | +apiVersion: v1 |
| 105 | +kind: DeploymentConfig |
| 106 | +metadata: |
| 107 | + name: frontend |
| 108 | +spec: |
| 109 | + replicas: 5 |
| 110 | + selector: |
| 111 | + name: frontend |
| 112 | + template: { ... } |
| 113 | + triggers: |
| 114 | + - type: ConfigChange <1> |
| 115 | + - imageChangeParams: |
| 116 | + automatic: true |
| 117 | + containerNames: |
| 118 | + - helloworld |
| 119 | + from: |
| 120 | + kind: ImageStreamTag |
| 121 | + name: hello-openshift:latest |
| 122 | + type: ImageChange <2> |
| 123 | + strategy: |
| 124 | + type: Rolling <3> |
| 125 | +---- |
| 126 | + |
| 127 | +1. A `*ConfigChange*` trigger causes a new deployment to be created any time the replication controller template changes. |
| 128 | +2. An `*ImageChange*` trigger causes a new deployment to be created each time a new version of the backing image is available in the named image stream. |
| 129 | +3. The default `*Rolling*` strategy makes a downtime-free transition between deployments. |
71 | 130 |
|
72 |
| -See the |
73 |
| -https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/replication-controller.md[Kubernetes |
74 |
| -documentation] for more on replication controllers. |
|
0 commit comments