kubeadm Documentation
repository·main·Indexed 24 days ago
https://github.com/kubernetes/kubeadmA tool used to bootstrap Kubernetes clusters following best practices. kubeadm automates the deployment of secure, minimum viable clusters by managing the local node filesystem and interacting with the Kubernetes API. It provides core commands for cluster lifecycle management, including kubeadm init for control-plane bootstrapping, kubeadm join for adding nodes, kubeadm upgrade for version updates, and kubeadm reset to revert host changes.
What's inside kubeadm
- Kubeadm is a tool designed to provide best-practice "fast paths" for creating Kubernetes clusters. It automates the actions necessary to deploy a minimum viable, secure cluster. Its scope is limited to the local node filesystem and the Kubernetes API, making it a composable building block for higher-level orchestration tools.
Implement Software Load Balancing for API Servers
mainIf your environment does not provide a managed load balancer (e.g., from a cloud provider), you must implement user-managed software load balancing.
Common strategies include:
- Using dedicated load balancing hardware/software provided by your data center.
- Setting up a cluster of hosts to manage a Virtual IP (vIP). In this setup, each host runs a load balancer instance, and only the host currently holding the vIP is active, while others remain on standby.
- Using tools like
keepalivedandhaproxyto manage the vIP and traffic distribution.
Understand the scope and workflow of kubeadm
mainkubeadm provides a user experience for creating a best-practice, bare Kubernetes cluster from scratch using
kubeadm initandkubeadm join.Key characteristics of a kubeadm-bootstrapped cluster:
- Secure: Enforces RBAC, uses the Node Authorizer, and ensures secure communication between control plane components, the API Server, and kubelets. It also locks down access to system components (kube-proxy, kube-dns) and Bootstrap Tokens.
- Easy to use: Requires minimal commands to get a cluster running.
- Extendable: Does not favor a specific network provider (network configuration is out-of-scope) and provides a configuration file for customizing parameters.
Important Design Principle: Every phase of the kubeadm execution must be idempotent.
Understand the TLS Bootstrap process in `kubeadm join`
mainAfter cluster discovery,
kubeadm joinperforms TLS Bootstrapping to allow the kubelet to authenticate securely:kubeadmwrites abootstrap-kubelet.conffile.- The kubelet uses the shared token to temporarily authenticate with the Kubernetes Master.
- The kubelet submits a Certificate Signing Request (CSR) for a locally created key pair.
- The CSR is automatically approved (managed by the
csrapprovercontroller). - Upon approval,
ca.crtandkubelet.confare saved for the kubelet to use, andbootstrap-kubelet.confis deleted.
Authentication Details:
- Temporary authentication is validated against the token saved during
kubeadm initor tokens created viakubeadm token. - The temporary authentication resolves to a user in the
system:bootstrappers:kubeadm:default-node-tokengroup, which is granted CSR API access duringkubeadm init.
Choose between kind and kinder
mainDecide which tool to use based on your requirements for Kubernetes cluster management:
- Use kind when you need a working Kubernetes cluster for standard development, testing, or CI/CD workflows where you simply want to interact with a cluster.
- Use kinder when you need granular control over the creation process of a Kubernetes cluster from "bare machines" (running as containers). It is specifically designed for
kubeadmcontributors andkubeadmE2E testing, allowing for more complex configurations like external etcd, external load balancers, and custom image manipulation.
Understand `kubeadm join` execution phases
mainWhen running
kubeadm join, the tool follows these phases:- Phase 1: Fetch the
cluster-infoConfigMap: The node attempts to fetch thecluster-infoConfigMap from thekube-publicnamespace viaGET /api/v1/namespaces/kube-public/configmaps/cluster-info. This phase is skipped if the ConfigMap is not public or if the user provides the cluster information via a local file. - Phase 2: TLS Bootstrap flow: The node posts a Certificate Signing Request (CSR) to the API server. Once approved and signed by the controller-manager,
kubeadmwrites the signed credentials to/etc/kubernetes/kubelet.conffor the kubelet to use.
- Phase 1: Fetch the
Understand `kubeadm init` execution phases
mainWhen running
kubeadm init, the tool executes a sequence of phases to bootstrap the control plane:- Phase 1: Generate certificates: Creates CA and component certificates (API Server, Kubelet client, ServiceAccount signing keys, etc.). By default, these are stored in
/etc/kubernetes/pki. - Phase 2: Generate KubeConfig files: Creates configuration files for master components (
/etc/kubernetes/admin.conf,/etc/kubernetes/kubelet.conf,/etc/kubernetes/controller-manager.conf, and/etc/kubernetes/scheduler.conf). - Phase 3: Bootstrap control plane via Static Pods: Spins up
etcd, the API Server, Controller Manager, and Scheduler as Static Pods. - Phase 4+: Post-bootstrap: Performs tasks like marking the node as a master, creating the
cluster-infoConfigMap, self-hosting manifests as DaemonSets, and deployingkube-proxyandkube-dns.
- Phase 1: Generate certificates: Creates CA and component certificates (API Server, Kubelet client, ServiceAccount signing keys, etc.). By default, these are stored in
Build control plane docker images locally
mainTo build control plane docker images from the Kubernetes source tree, use the
makecommands within the${GOPATH}/src/k8s.io/kubernetesdirectory.cd ${GOPATH}/src/k8s.io/kubernetes # Build docker images only for linux/amd64 make quick-release-images # Build all docker images make release-imagesRun kubeadm E2E tests with kinder
mainUse
kinder test e2e-kubeadmto run a suite of tests that checks ifkubeadmhas correctly created and configured the necessary ConfigMaps, Secrets, RBAC Roles, and RoleBindings required forkubeadm joinorkubeadm upgradeoperations. Tests are executed against the cluster defined in your currentkubeconfigfile.Supported flags:
--kube-root: Set the folder where the Kubernetes sources are stored.--single-node: Instruct the Ginkgo test suite to skip tests labeled with[multi-node].--automatic-copy-certs: Instruct the Ginkgo test suite to skip tests labeled with[copy-certs].
kinder test e2e-kubeadmImplement High Availability with kube-vip
mainAs an alternative to
keepalivedandhaproxy,kube-vipprovides both Virtual IP (VIP) management and load balancing in a single service. It can be deployed as a static pod on control plane nodes using either Layer 2 (ARP withleaderElection) or Layer 3 (BGP peering).Requirements & Constraints:
- Hosts negotiating a VIP must be in the same IP subnet.
kube-viprequires access to the API server. Duringkubeadm init, it uses theadmin.confkubeconfig. Post-setup, it is recommended to use a custom client kubeconfig and rotate it manually upon expiration.- For Kubernetes v1.29+, since
admin.confis not immediately usable during bootstrap, consider usingsuper-admin.conffor initialization and switching toadmin.confonce complete.
Add a new kubeadm sub-command to the documentation
mainSince
kubeadmuses Cobra, command line reference documentation is generated automatically. To add a new sub-command to the official Kubernetes website documentation, follow these steps:- Implement the sub-command in the
kubernetes/kubernetesrepository. - Run the documentation generation script locally:
./hack/update-generated-docs.sh. This generates files in./docs/admin/. - In a local copy of the
kubernetes/websiterepository, navigate to./content/en/docs/reference/setup-tools/kubeadm/generated. - Copy the newly generated files (e.g.,
*newcommand*.md) fromkubernetes/docs/admin/to the website's generated folder. - In the parent command's Markdown file, import the new sub-command using a shortcode include. For example, if adding a sub-command to
kubeadm config, add the following to thekubeadm-config.mdfile:
## kubeadm config view {#cmd-config-newcommand} {{< include "generated/kubeadm_config_newcommand.md" >}}- Submit a PR to
kubernetes/websitecontaining the new files and the updated parent command file.
Note: These files act as placeholders in
kubernetes/websiteand will be overwritten by a separate tool managed by SIG Docs during each release../hack/update-generated-docs.sh- Implement the sub-command in the
Validate a kinder cluster
mainAfter initializing your cluster, use the following commands to verify the state and run tests:
- Cluster Overview: Run
kinder do cluster-infoto check for nodes (status:Ready), verify Kubernetes version and component dependencies, and check etcd membership. - Smoke Test: Run
kinder do smoke-testto execute a basic functional test of the cluster.
Note: You can use the
--only-nodeflag withkinder doto execute these validation actions on a specific node. Alternatively, you can usedocker execanddocker cpto runkubeadm,kubectl, or other shell commands directly on the nodes.# get an overview of the resulting cluster kinder do cluster-info # run a smoke test kinder do smoke-test- Cluster Overview: Run