|
2 | 2 | title: "Configuration"
|
3 | 3 | weight: 80
|
4 | 4 | description: >
|
5 |
| - Resources that Kubernetes provides for configuring Pods. |
| 5 | + Configuration mechanisms within Kubernetes. |
| 6 | +simple_list: true |
6 | 7 | ---
|
7 | 8 |
|
| 9 | +Kubernetes provides ways to _separate configuration from code_. This is a common |
| 10 | +practice that aligns with DevOps as a practice, and with cloud native architecture. |
| 11 | + |
| 12 | +If you have a {{< glossary_tooltip text="container image" term_id="image" >}} that |
| 13 | +allows separate configuration, you can deploy the **same** application code in |
| 14 | +different contexts. For example, you can run tests against the built image, and |
| 15 | +then run that exact same image in a production context. Doing that gives you |
| 16 | +better confidence in your testing, compared with if you deployed the application |
| 17 | +one way for tests and a different way in production. |
| 18 | + |
| 19 | +If you wanted to learn about configuring the `kubectl` command line tool, |
| 20 | +read [configure access to multiple clusters](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/). |
| 21 | + |
| 22 | +<!-- body --> |
| 23 | +## Kubernetes configuration-related APIs {#api-kinds} |
| 24 | + |
| 25 | +Kubernetes provides two main API kinds that you can use to store configuration, |
| 26 | +ready for a Pod (or other component) to load and use: |
| 27 | +[ConfigMap](/docs/concepts/configuration/configmap/), and |
| 28 | +[Secret](/docs/concepts/configuration/secret/). |
| 29 | + |
| 30 | +The special-use |
| 31 | +[CertificateSigningRequest](/docs/reference/access-authn-authz/certificate-signing-requests/#certificate-signing-requests) |
| 32 | +and |
| 33 | +[ClusterTrustBundle](/docs/reference/access-authn-authz/certificate-signing-requests/#cluster-trust-bundles) |
| 34 | +API kinds also hold configuration data that's relevant to some specific cases, |
| 35 | +such as TLS configuration. |
| 36 | + |
| 37 | +All of these mechanisms can be shared across multiple Pods. You typically don't |
| 38 | +have to write the configuration out once per Pod, and you should design applications |
| 39 | +where possible so that they can work with shared configuration. |
| 40 | + |
| 41 | +To learn about using configuration in your applications, read |
| 42 | +[inject data into applications](/docs/tasks/inject-data-application/). |
| 43 | + |
| 44 | +### ConfigMaps |
| 45 | + |
| 46 | +{{< glossary_definition term_id="configmap" prepend="A ConfigMap is" length="all" >}} |
| 47 | + |
| 48 | +### Secrets |
| 49 | + |
| 50 | +A Secret is an object that contains an amount of confidential data, |
| 51 | +such as a password, a token, or a key. |
| 52 | + |
| 53 | +Secrets are similar to {{< glossary_tooltip text="ConfigMaps" term_id="configmap" >}} |
| 54 | +but are specifically intended to hold confidential data. Read the page about Secrets |
| 55 | +to learn about the benefits (and limitations) around information security and Secrets. |
| 56 | + |
| 57 | +## Configuration via helper containers {#config-helper-overview} |
| 58 | + |
| 59 | +You can also use an |
| 60 | +{{< glossary_tooltip text="init container" term_id="init-container" >}} or a |
| 61 | +{{< glossary_tooltip text="sidecar container" term_id="sidecar-container" >}} |
| 62 | +to provide configuration to your workload. |
| 63 | + |
| 64 | +This is useful if you already have some means, outside of Kubernetes, to store |
| 65 | +configuration or security keys or other information that your containers must |
| 66 | +use, and that shouldn't be stored in container images. |
| 67 | + |
| 68 | +### Sidecar container helper {#config-helper-sidecar} |
| 69 | + |
| 70 | +A _sidecar_ configuration helper runs in the same Pod as the application container, so |
| 71 | +each Pod has its own sidecar. A typical configuration sidecar fetches configuration data over the |
| 72 | +Pod network, and then writes it into a {{< glossary_tooltip text="volume" term_id="volume" >}} |
| 73 | +that is mounted into both containers. |
| 74 | + |
| 75 | +There are many variations on this basic pattern, that still have a helper |
| 76 | +container writing configuration for the app container to consume. |
| 77 | + |
| 78 | +### Init container helper {#config-helper-init-container} |
| 79 | + |
| 80 | +Pods can have _init_ containers that start before the main application. Unlike sidecars, |
| 81 | +init containers complete before the Pod's main (application) containers start up, so the |
| 82 | +configuration only gets set once. |
| 83 | + |
| 84 | +You have two main options for configuration using init containers: |
| 85 | + |
| 86 | +#### Configuration via the filesystem {#init-container-shared-volume} |
| 87 | + |
| 88 | +With this option, the init container fetches configuration and writes the configuration to |
| 89 | +a file, or several files, typically to a Pod-local |
| 90 | +{{< glossary_tooltip text="volume" term_id="volume" >}}. |
| 91 | + |
| 92 | +#### Configuration via environment variables {#init-container-env-files} |
| 93 | + |
| 94 | +{{< feature-state feature_gate_name="EnvFiles" >}} |
| 95 | + |
| 96 | +This is done using a local volume, but only the init container mounts that volume. The kubelet then reads from that volume before starting the app container. |
| 97 | + |
| 98 | +Read [Define Environment Variable Values Using An Init Container](/docs/tasks/inject-data-application/define-environment-variable-via-file/) |
| 99 | +to learn more. |
| 100 | + |
| 101 | +## Cluster configuration |
| 102 | + |
| 103 | +Depending on the role you have, you may also need to configure your cluster. |
| 104 | +To learn more about that, read |
| 105 | +[cluster administration](/docs/concepts/cluster-administration/) and |
| 106 | +look through the list of [cluster administration tasks](/docs/tasks/administer-cluster/). |
| 107 | + |
| 108 | +## {{% heading "whatsnext" %}} |
| 109 | + |
| 110 | +The following links are all relevant to the overall idea of _configuration_ and Kubernetes: |
| 111 | + |
| 112 | +* [Management of Kubernetes Objects Using Configuration Files](/docs/tasks/manage-kubernetes-objects/declarative-config/), |
| 113 | + which is about Kubernetes {{< glossary_tooltip text="manifests" term_id="manifest" >}} |
| 114 | + * [Kubernetes Object Management](/docs/concepts/overview/working-with-objects/object-management/) is also about object management / configuration |
| 115 | +* [Configure Redis Using A ConfigMap](/docs/tutorials/configuration/configure-redis-using-configmap/). |
| 116 | + a tutorial |
| 117 | +* [Updating Configuration via a ConfigMap](/docs/tutorials/configuration/updating-configuration-via-a-configmap/) |
| 118 | + (another tutorial) |
| 119 | +* [Inject Data Into Applications](/docs/tasks/inject-data-application/) |
| 120 | +* [Configure Pods and Containers](/docs/tasks/configure-pod-container/) |
| 121 | +* [Cluster Administration](/docs/concepts/cluster-administration/) |
| 122 | + * [API server authentication configuration](/docs/reference/access-authn-authz/authentication/#using-authentication-configuration) |
| 123 | + * [API server authorization configuration](/docs/reference/access-authn-authz/authorization/#using-configuration-file-for-authorization) |
| 124 | + * [Configure Certificate Rotation for the Kubelet](/docs/tasks/tls/certificate-rotation/) |
| 125 | + * [Reconfiguring a `kubeadm` Cluster](/docs/tasks/administer-cluster/kubeadm/kubeadm-reconfigure/) |
| 126 | + * [Configuring a CGroup Driver](/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/) |
| 127 | + * [Create Static Pods](/docs/tasks/configure-pod-container/static-pod/), relevant to |
| 128 | + control plane configuration |
| 129 | + * [Configure the Aggregation Layer](/docs/tasks/extend-kubernetes/configure-aggregation-layer/) |
| 130 | +* [Policies](/docs/concepts/policy/), another form of configuration |
| 131 | + |
| 132 | +and you can review the [list of configuration file formats](/docs/reference/config-api/) |
| 133 | +in the reference section. |
| 134 | + |
| 135 | +Within **this** section of the documentation, you can read about: |
0 commit comments