--- approvers: - mikedanese - luxas - errordeveloper - jbeda title: Kubeadm notitle: true --- # kubeadm Setup Tool Reference Guide This document provides information on how to use kubeadm's advanced options. * TOC {:toc} Running `kubeadm init` bootstraps a Kubernetes master node. This consists of the following steps: 1. kubeadm runs a series of pre-flight checks to validate the system state before making changes. Some checks only trigger warnings, others are considered errors and will exit kubeadm until the problem is corrected or the user specifies `--skip-preflight-checks`. 1. kubeadm generates a token that additional nodes can use to register themselves with the master in future. Optionally, the user can provide a token via `--token`, as described in the [section on managing tokens](#manage-tokens) below. 1. kubeadm generates a self-signed CA to provision identities for each component (including nodes) in the cluster. It also generates client certificates to be used by various components. If the user has provided their own CA by dropping it in the cert directory configured via `--cert-dir` (`/etc/kubernetes/pki` by default) this step is skipped as described in the [section on using custom certificates](#custom-certificates). 1. kubeadm writes kubeconfig files in `/etc/kubernetes/` for the kubelet, the controller-manager and the scheduler to use to connect to the API server, each one with their respective identities, as well as an additional kubeconfig file for administration. 1. kubeadm generates static Pod manifests for the API server, controller manager and scheduler; in case an external etcd is not provided, an additional static Pod manifest will be generated for etcd. Static Pod manifests are written in `/etc/kubernetes/manifests`; the kubelet watches this directory for Pods to create on startup, as described in the [section about kubelet drop-in](#kubelet-drop-in). Once control plane Pods are up and running kubeadm init sequence can continue. 1. kubeadm "labels" and "taints" the master node so that only control plane components will run there. 1. Kubeadm makes all the necessary configurations for allowing node joining with the [Bootstrap Tokens](https://kubernetes.io/docs/admin/bootstrap-tokens/) and [TLS Bootstrap](https://kubernetes.io/docs/admin/kubelet-tls-bootstrapping/) mechanism: - Write a ConfigMap for making available all the information required for joining and set up related RBAC access rules. - Ensure access to the CSR signing API for bootstrap tokens. - Configure auto approval for new CSR requests. See [Securing your installation](#securing-more) for hardening. 1. kubeadm installs add-on components via the API server. Right now this is the internal DNS server and the kube-proxy DaemonSet. 1. If `kubeadm init` is invoked with the alpha self-hosting feature enabled, (`--feature-gates=SelfHosting=true`), the static Pod based control plane will be transformed in a [self-hosed control plane](#self-hosting). Running `kubeadm join` on each node in the cluster consists of the following steps: 1. kubeadm downloads necessary cluster information from the API server. By default, it uses the bootstrap token and the CA key hash to verify the authenticity of that data. The root CA can also be discovered directly via a file or URL. 1. Once the cluster information are known, kubelet can start the TLS bootstrapping process (in v.1.7 this step was managed by kubeadm). The TLS bootstrap uses the shared token to temporarily authenticate with the Kubernetes Master to submit a certificate signing request (CSR); by default the control plane will sign this CSR request automatically. 1. Finally, kubeadm will configures the local kubelet to connect to the API server with the definitive identity assigned to the node. ## Usage Fields that support multiple values do so either with comma separation, or by specifying the flag multiple times. The kubeadm command line interface is currently in **beta**. We are aiming to not break any scripted use of the main `kubeadm init` and `kubeadm join`. Exceptions to this are documented below. ### `kubeadm init` It is usually sufficient to run `kubeadm init` without any flags, but in some cases you might like to override the default behaviour. Here we specify all the flags that can be used to customise the Kubernetes installation. **Options for `kubeadm init`:** - `--apiserver-advertise-address` This is the address the API Server will advertise to other members of the cluster. This is also the address used to construct the suggested `kubeadm join` line at the end of the init process. If not set (or set to 0.0.0.0) then IP for the default interface will be used. This address is also added to the certificate that the API Server uses. - `--apiserver-bind-port` The port that the API server will bind on. This defaults to 6443. - `--apiserver-cert-extra-sans` Additional hostnames or IP addresses that should be added to the Subject Alternate Name section for the certificate that the API Server will use. If you expose the API Server through a load balancer and public DNS you could specify this with ``` --apiserver-cert-extra-sans=kubernetes.example.com,kube.example.com,10.100.245.1 ``` - `--cert-dir` The path where to save and store the certificates. The default is "/etc/kubernetes/pki". - `--config` A kubeadm specific [config file](#config-file). This can be used to specify an extended set of options including passing arbitrary command line flags to the control plane components. **Note**: Since 1.8, other flags are not allowed alongside `--config` except for flags used to define kubeadm behaviour (not configuration) such as `--skip-preflight-checks`. - `--dry-run` This flag tells kubeadm to don't apply any changes; just output what would be done. - `--feature-gates` A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: - SelfHosting=true|false (ALPHA - default=false) - StoreCertsInSecrets=true|false (ALPHA - default=false) See [self-hosted control plane](#self-hosting) for more detail. - `--kubernetes-version` (default 'latest') the kubernetes version to initialise The **v1.6** version of kubeadm only supports building clusters that are at least **v1.6.0**. There are many reasons for this including kubeadm's use of RBAC, the Bootstrap Token system, and enhancements to the Certificates API. With this flag you can try any future version of Kubernetes. Check [releases page](https://github.com/kubernetes/kubernetes/releases) for a full list of available versions. - `--node-name` Allow to specify the node name, if something different than O.S. hostname should be used e.g. in case of Amazon EC2 instances. The node-name is also added to the certificate that the API Server uses. - `--pod-network-cidr` For certain networking solutions the Kubernetes master can also play a role in allocating network ranges (CIDRs) to each node. This includes many cloud providers and flannel. You can specify a subnet range that will be broken down and handed out to each node with the `--pod-network-cidr` flag. This should be a minimum of a /16 so controller-manager is able to assign /24 subnets to each node in the cluster. If you are using flannel with [this manifest](https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml) you should use `--pod-network-cidr=10.244.0.0/16`. Most CNI based networking solutions do not require this flag. - `--service-cidr` (default '10.96.0.0/12') You can use the `--service-cidr` flag to override the subnet Kubernetes uses to assign pods IP addresses. If you do, you will also need to update the `/etc/systemd/system/kubelet.service.d/10-kubeadm.conf` file to reflect this change else DNS will not function correctly. - `--service-dns-domain` (default 'cluster.local') By default, `kubeadm init` deploys a cluster that assigns services with DNS names `..svc.cluster.local`. You can use the `--service-dns-domain` to change the DNS name suffix. Again, you will need to update the `/etc/systemd/system/kubelet.service.d/10-kubeadm.conf` file accordingly else DNS will not function correctly. **Note**: This flag has an effect (it's needed for the kube-dns Deployment manifest and the API Server's serving certificate) but not as you might expect, since you will have to modify the arguments to the kubelets in the cluster for it to work fully. Specifying DNS parameters using this flag only is not enough. Rewriting the kubelet's CLI arguments is out of scope for kubeadm as it should be agnostic to how you run the kubelet. However, making all kubelets in the cluster pick up information dynamically via the API _is_ in scope and is a [planned feature](https://github.com/kubernetes/kubeadm/issues/28) for upcoming releases. - `--skip-preflight-checks` By default, kubeadm runs a series of preflight checks to validate the system before making any changes. Advanced users can use this flag to bypass these if necessary. - `--skip-token-print` By default, kubeadm prints the token at the end of the init procedure. Advanced users can use this flag to bypass these if necessary. - `--token` By default, `kubeadm init` automatically generates the token used to initialise each new node. If you would like to manually specify this token, you can use the `--token` flag. The token must be of the format `[a-z0-9]{6}\.[a-z0-9]{16}`. A compatible random token can be generated `kubeadm token generate`. Tokens can be managed through the API after the cluster is created. See the [section on managing tokens](#manage-tokens) below. - `--token-ttl` This sets an expiration time for the token. This is specified as a duration from the current time. After this time the token will no longer be valid and will be removed. A value of 0 specifies that the token never expires. The default is 24 hours. See the [section on managing tokens](#manage-tokens) below. ### `kubeadm join` When joining a kubeadm initialized cluster, we need to establish bidirectional trust. This is split into discovery (having the Node trust the Kubernetes master) and TLS bootstrap (having the Kubernetes master trust the Node). There are two main schemes for discovery: - **Using a shared token** along with the IP address of the API server and a hash of the root CA key: `kubeadm join --discovery-token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:1234..cdef 1.2.3.4:6443` - **Using a file** (a subset of the standard kubeconfig file). This file can be a local file or downloaded via an HTTPS URL: `kubeadm join --discovery-file path/to/file.conf` `kubeadm join --discovery-file https://url/file.conf` Only one form can be used. If the discovery information is loaded from a URL, HTTPS must be used and the host installed CA bundle is used to verify the connection. For details on the security tradeoffs of these mechanisms, see the [security model](#security-model) section below. The TLS bootstrap mechanism is also driven via a shared token. This is used to temporarily authenticate with the Kubernetes master to submit a certificate signing request (CSR) for a locally created key pair. By default kubeadm will set up the Kubernetes master to automatically approve these signing requests. This token is passed in with the `--tls-bootstrap-token abcdef.1234567890abcdef` flag. Often times the same token is used for both parts. In this case, the `--token` flag can be used instead of specifying the each token individually. Here's an example on how to use it: `kubeadm join --token=abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:1234..cdef 192.168.1.1:6443` **Options for `kubeadm join`:** - `--config` Extended options are specified in the [kubeadm specific config file](#config-file). - `--discovery-file` A local file path or HTTPS URL. The file specified must be a kubeconfig file with nothing but an unnamed cluster entry. This is used to find both the location of the API server to join along with a root CA bundle to use when talking to that server. This might look something like this: ``` yaml apiVersion: v1 clusters: - cluster: certificate-authority-data: server: https://10.138.0.2:6443 name: "" contexts: [] current-context: "" kind: Config preferences: {} users: [] ``` - `--discovery-token` The discovery token is used along with the address of the API server (as an unnamed argument) to download and verify information about the cluster. The most critical part of the cluster information is the root CA bundle used to verify the identity of the server during subsequent TLS connections. - `--discovery-token-ca-cert-hash` The CA key hash is used to verify the full root CA certificate discovered during token-based bootstrapping. It has the format `sha256:`. By default, the hash value is returned in the `kubeadm join` command printed at the end of `kubeadm init`. It is in a standard format (see [RFC7469](https://tools.ietf.org/html/rfc7469#section-2.4)) and can also be calculated by 3rd party tools or provisioning systems. For example, using the OpenSSL CLI: `openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>&/dev/null | openssl dgst -sha256 -hex` _Skipping this flag is allowed in Kubernetes 1.8, but makes certain spoofing attacks possible._ See the [security model](#security-model) for details. Pass `--discovery-token-unsafe-skip-ca-verification` to silence warnings (which will become errors in Kubernetes 1.9). - `--discovery-token-unsafe-skip-ca-verification` Disable the warning/error that occurs when `--discovery-token-ca-cert-hash` is not provided. Passing this flag is an acknowledgement of the [security tradeoffs](#security-model) involved in skipping this verification (which may or may not be appropriate in your environment). - `--node-name` Specify the Node name. The default is to use the OS hostname. This is useful on some cloud providers such as AWS. This name is also added to the node's TLS certificate. - `--tls-bootstrap-token` The token used to authenticate to the API server for the purposes of TLS bootstrapping. - `--token=` Often times the same token is used for both `--discovery-token` and `--tls-bootstrap-token`. This option specifies the same token for both. Other flags override this flag if present. - `--skip-preflight-checks` By default, kubeadm runs a series of preflight checks to validate the system before making any changes. Advanced users can use this flag to bypass these if necessary. ### `kubeadm completion` Output shell completion code for the specified shell (bash or zsh). ### `kubeadm config` Kubeadm v1.8.0+ automatically creates a ConfigMap with all the parameters used during `kubeadm init`. If you initialized your cluster using kubeadm v1.7.x or lower, you must use the `kubeadm config upload` command to create this ConfigMap in order for `kubeadm upgrade` to be able to configure your upgraded cluster correctly. ### `kubeadm reset` Reverts any changes made to this host by `kubeadm init` or `kubeadm join`. ### `kubeadm token` Manage tokens on a running cluster. See [managing tokens](#manage-tokens) below for further details. ### `kubeadm alpha phases` **WARNING:** While kubeadm command line interface is in beta, commands under this entry is still considered alpha and may change in future versions. `kubeadm phase` introduces a set of kubeadm CLI commands allowing to invoke individually each phase of the kubeadm init sequence; phases provide a reusable and composable API/toolbox for building your own automated cluster installer. **Options for `kubeadm phases`:** Each kubeadm phase exposes a subset of relevant options from `kubeadm init`. ## Using kubeadm with a configuration file {#config-file} **WARNING:** While kubeadm command line interface is in beta, the config file is still considered alpha and may change in future versions. It's possible to configure kubeadm with a configuration file instead of command line flags, and some more advanced features may only be available as configuration file options. This file is passed in to the `--config` option on both `kubeadm init` and `kubeadm join`. ### Sample Master Configuration ```yaml apiVersion: kubeadm.k8s.io/v1alpha1 kind: MasterConfiguration api: advertiseAddress: bindPort: etcd: endpoints: - - caFile: certFile: keyFile: dataDir: extraArgs: : : image: networking: dnsDomain: serviceSubnet: podSubnet: kubernetesVersion: cloudProvider: nodeName: authorizationModes: - - token: tokenTTL: