You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/concepts/configuration/overview.md
+86-33Lines changed: 86 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,79 +7,132 @@ weight: 10
7
7
---
8
8
9
9
<!-- overview -->
10
-
This document highlights and consolidates configuration best practices that are introduced throughout the user guide, Getting Started documentation, and examples.
11
-
12
-
This is a living document. If you think of something that is not on this list but might be useful to others, please don't hesitate to file an issue or submit a PR.
10
+
This document highlights and consolidates configuration best practices that are introduced
11
+
throughout the user guide, Getting Started documentation, and examples.
13
12
13
+
This is a living document. If you think of something that is not on this list but might be useful
14
+
to others, please don't hesitate to file an issue or submit a PR.
14
15
15
16
<!-- body -->
16
17
## General Configuration Tips
17
18
18
19
- When defining configurations, specify the latest stable API version.
19
20
20
-
- Configuration files should be stored in version control before being pushed to the cluster. This allows you to quickly roll back a configuration change if necessary. It also aids cluster re-creation and restoration.
21
+
- Configuration files should be stored in version control before being pushed to the cluster. This
22
+
allows you to quickly roll back a configuration change if necessary. It also aids cluster
23
+
re-creation and restoration.
21
24
22
-
- Write your configuration files using YAML rather than JSON. Though these formats can be used interchangeably in almost all scenarios, YAML tends to be more user-friendly.
25
+
- Write your configuration files using YAML rather than JSON. Though these formats can be used
26
+
interchangeably in almost all scenarios, YAML tends to be more user-friendly.
23
27
24
-
- Group related objects into a single file whenever it makes sense. One file is often easier to manage than several. See the [guestbook-all-in-one.yaml](https://github.com/kubernetes/examples/tree/master/guestbook/all-in-one/guestbook-all-in-one.yaml) file as an example of this syntax.
28
+
- Group related objects into a single file whenever it makes sense. One file is often easier to
- Note also that many `kubectl` commands can be called on a directory. For example, you can call `kubectl apply` on a directory of config files.
33
+
- Note also that many `kubectl` commands can be called on a directory. For example, you can call
34
+
`kubectl apply` on a directory of config files.
27
35
28
36
- Don't specify default values unnecessarily: simple, minimal configuration will make errors less likely.
29
37
30
38
- Put object descriptions in annotations, to allow better introspection.
31
39
32
-
33
40
## "Naked" Pods versus ReplicaSets, Deployments, and Jobs {#naked-pods-vs-replicasets-deployments-and-jobs}
34
41
35
-
- Don't use naked Pods (that is, Pods not bound to a [ReplicaSet](/docs/concepts/workloads/controllers/replicaset/) or[Deployment](/docs/concepts/workloads/controllers/deployment/)) if you can avoid it. Naked Pods will not be rescheduled in the event of a node failure.
36
-
37
-
A Deployment, which both creates a ReplicaSet to ensure that the desired number of Pods is always available, and specifies a strategy to replace Pods (such as [RollingUpdate](/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment)), is almost always preferable to creating Pods directly, except for some explicit [`restartPolicy: Never`](/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy) scenarios. A [Job](/docs/concepts/workloads/controllers/job/) may also be appropriate.
42
+
- Don't use naked Pods (that is, Pods not bound to a [ReplicaSet](/docs/concepts/workloads/controllers/replicaset/) or
43
+
[Deployment](/docs/concepts/workloads/controllers/deployment/)) if you can avoid it. Naked Pods
44
+
will not be rescheduled in the event of a node failure.
38
45
46
+
A Deployment, which both creates a ReplicaSet to ensure that the desired number of Pods is
47
+
always available, and specifies a strategy to replace Pods (such as
48
+
[RollingUpdate](/docs/concepts/workloads/controllers/deployment/#rolling-update-deployment)), is
49
+
almost always preferable to creating Pods directly, except for some explicit
A [Job](/docs/concepts/workloads/controllers/job/) may also be appropriate.
39
52
40
53
## Services
41
54
42
-
- Create a [Service](/docs/concepts/services-networking/service/) before its corresponding backend workloads (Deployments or ReplicaSets), and before any workloads that need to access it. When Kubernetes starts a container, it provides environment variables pointing to all the Services which were running when the container was started. For example, if a Service named `foo` exists, all containers will get the following variables in their initial environment:
55
+
- Create a [Service](/docs/concepts/services-networking/service/) before its corresponding backend
56
+
workloads (Deployments or ReplicaSets), and before any workloads that need to access it.
57
+
When Kubernetes starts a container, it provides environment variables pointing to all the Services
58
+
which were running when the container was started. For example, if a Service named `foo` exists,
59
+
all containers will get the following variables in their initial environment:
43
60
44
61
```shell
45
62
FOO_SERVICE_HOST=<the host the Service is running on>
46
63
FOO_SERVICE_PORT=<the port the Service is running on>
47
64
```
48
65
49
-
*This does imply an ordering requirement* - any `Service` that a `Pod` wants to access must be created before the `Pod` itself, or else the environment variables will not be populated. DNS does not have this restriction.
66
+
*This does imply an ordering requirement* - any `Service` that a `Pod` wants to access must be
67
+
created before the `Pod` itself, or else the environment variables will not be populated.
68
+
DNS does not have this restriction.
50
69
51
-
- An optional (though strongly recommended) [cluster add-on](/docs/concepts/cluster-administration/addons/) is a DNS server. The
52
-
DNS server watches the Kubernetes API for new `Services` and creates a set of DNS records for each. If DNS has been enabled throughout the cluster then all `Pods` should be able to do name resolution of `Services` automatically.
70
+
- An optional (though strongly recommended) [cluster add-on](/docs/concepts/cluster-administration/addons/)
71
+
is a DNS server. The DNS server watches the Kubernetes API for new `Services` and creates a set
72
+
of DNS records for each. If DNS has been enabled throughout the cluster then all `Pods` should be
73
+
able to do name resolution of `Services` automatically.
53
74
54
-
- Don't specify a `hostPort` for a Pod unless it is absolutely necessary. When you bind a Pod to a `hostPort`, it limits the number of places the Pod can be scheduled, because each <`hostIP`, `hostPort`, `protocol`> combination must be unique. If you don't specify the `hostIP` and `protocol` explicitly, Kubernetes will use `0.0.0.0` as the default `hostIP` and `TCP` as the default `protocol`.
75
+
- Don't specify a `hostPort` for a Pod unless it is absolutely necessary. When you bind a Pod to a
76
+
`hostPort`, it limits the number of places the Pod can be scheduled, because each <`hostIP`,
77
+
`hostPort`, `protocol`> combination must be unique. If you don't specify the `hostIP` and
78
+
`protocol` explicitly, Kubernetes will use `0.0.0.0` as the default `hostIP` and `TCP` as the
79
+
default `protocol`.
55
80
56
-
If you only need access to the port for debugging purposes, you can use the [apiserver proxy](/docs/tasks/access-application-cluster/access-cluster/#manually-constructing-apiserver-proxy-urls) or [`kubectl port-forward`](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/).
81
+
If you only need access to the port for debugging purposes, you can use the
or [`kubectl port-forward`](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/).
57
84
58
-
If you explicitly need to expose a Pod's port on the node, consider using a [NodePort](/docs/concepts/services-networking/service/#type-nodeport) Service before resorting to `hostPort`.
85
+
If you explicitly need to expose a Pod's port on the node, consider using a
86
+
[NodePort](/docs/concepts/services-networking/service/#type-nodeport) Service before resorting to
87
+
`hostPort`.
59
88
60
89
- Avoid using `hostNetwork`, for the same reasons as `hostPort`.
61
90
62
-
- Use [headless Services](/docs/concepts/services-networking/service/#headless-services) (which have a `ClusterIP` of `None`) for service discovery when you don't need `kube-proxy` load balancing.
91
+
- Use [headless Services](/docs/concepts/services-networking/service/#headless-services)
92
+
(which have a `ClusterIP` of `None`) for service discovery when you don't need `kube-proxy`
93
+
load balancing.
63
94
64
95
## Using Labels
65
96
66
-
- Define and use [labels](/docs/concepts/overview/working-with-objects/labels/) that identify __semantic attributes__ of your application or Deployment, such as `{ app.kubernetes.io/name: MyApp, tier: frontend, phase: test, deployment: v3 }`. You can use these labels to select the appropriate Pods for other resources; for example, a Service that selects all `tier: frontend` Pods, or all `phase: test` components of `app.kubernetes.io/name: MyApp`. See the [guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) app for examples of this approach.
67
-
68
-
A Service can be made to span multiple Deployments by omitting release-specific labels from its selector. When you need to update a running service without downtime, use a [Deployment](/docs/concepts/workloads/controllers/deployment/).
69
-
70
-
A desired state of an object is described by a Deployment, and if changes to that spec are _applied_, the deployment controller changes the actual state to the desired state at a controlled rate.
71
-
72
-
- Use the [Kubernetes common labels](/docs/concepts/overview/working-with-objects/common-labels/) for common use cases. These standardized labels enrich the metadata in a way that allows tools, including `kubectl` and [dashboard](/docs/tasks/access-application-cluster/web-ui-dashboard), to work in an interoperable way.
73
-
74
-
- You can manipulate labels for debugging. Because Kubernetes controllers (such as ReplicaSet) and Services match to Pods using selector labels, removing the relevant labels from a Pod will stop it from being considered by a controller or from being served traffic by a Service. If you remove the labels of an existing Pod, its controller will create a new Pod to take its place. This is a useful way to debug a previously "live" Pod in a "quarantine" environment. To interactively remove or add labels, use [`kubectl label`](/docs/reference/generated/kubectl/kubectl-commands#label).
97
+
- Define and use [labels](/docs/concepts/overview/working-with-objects/labels/) that identify
98
+
__semantic attributes__ of your application or Deployment, such as `{ app.kubernetes.io/name:
99
+
MyApp, tier: frontend, phase: test, deployment: v3 }`. You can use these labels to select the
100
+
appropriate Pods for other resources; for example, a Service that selects all `tier: frontend`
101
+
Pods, or all `phase: test` components of `app.kubernetes.io/name: MyApp`.
102
+
See the [guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) app
103
+
for examples of this approach.
104
+
105
+
A Service can be made to span multiple Deployments by omitting release-specific labels from its
106
+
selector. When you need to update a running service without downtime, use a
A desired state of an object is described by a Deployment, and if changes to that spec are
110
+
_applied_, the deployment controller changes the actual state to the desired state at a controlled
111
+
rate.
112
+
113
+
- Use the [Kubernetes common labels](/docs/concepts/overview/working-with-objects/common-labels/)
114
+
for common use cases. These standardized labels enrich the metadata in a way that allows tools,
115
+
including `kubectl` and [dashboard](/docs/tasks/access-application-cluster/web-ui-dashboard), to
116
+
work in an interoperable way.
117
+
118
+
- You can manipulate labels for debugging. Because Kubernetes controllers (such as ReplicaSet) and
119
+
Services match to Pods using selector labels, removing the relevant labels from a Pod will stop
120
+
it from being considered by a controller or from being served traffic by a Service. If you remove
121
+
the labels of an existing Pod, its controller will create a new Pod to take its place. This is a
122
+
useful way to debug a previously "live" Pod in a "quarantine" environment. To interactively remove
123
+
or add labels, use [`kubectl label`](/docs/reference/generated/kubectl/kubectl-commands#label).
75
124
76
125
## Using kubectl
77
126
78
-
- Use `kubectl apply -f <directory>`. This looks for Kubernetes configuration in all `.yaml`, `.yml`, and `.json` files in `<directory>` and passes it to `apply`.
79
-
80
-
- Use label selectors for `get` and `delete` operations instead of specific object names. See the sections on [label selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors) and [using labels effectively](/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively).
81
-
82
-
- Use `kubectl create deployment` and `kubectl expose` to quickly create single-container Deployments and Services. See [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster/) for an example.
127
+
- Use `kubectl apply -f <directory>`. This looks for Kubernetes configuration in all `.yaml`,
128
+
`.yml`, and `.json` files in `<directory>` and passes it to `apply`.
83
129
130
+
- Use label selectors for `get` and `delete` operations instead of specific object names. See the
131
+
sections on [label selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors)
132
+
and [using labels effectively](/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively).
84
133
134
+
- Use `kubectl create deployment` and `kubectl expose` to quickly create single-container
135
+
Deployments and Services.
136
+
See [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster/)
0 commit comments