2017-08-29 00:19:25 +03:00
|
|
|
# Bootstrapping the Kubernetes Control Plane
|
|
|
|
|
2025-06-03 05:13:21 +03:00
|
|
|
In this lab you will bootstrap the Kubernetes control plane. The following
|
|
|
|
components will be installed on the `controlplane` machine: Kubernetes API
|
|
|
|
Server, Scheduler, and Controller Manager.
|
2017-08-29 00:19:25 +03:00
|
|
|
|
|
|
|
## Prerequisites
|
|
|
|
|
2025-06-03 05:13:21 +03:00
|
|
|
Connect to the `jumpbox` and copy Kubernetes binaries and systemd unit files
|
|
|
|
to the `controlplane` machine:
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
|
|
|
scp \
|
2025-04-10 09:08:13 +03:00
|
|
|
downloads/controller/kube-apiserver \
|
|
|
|
downloads/controller/kube-controller-manager \
|
|
|
|
downloads/controller/kube-scheduler \
|
|
|
|
downloads/client/kubectl \
|
2023-11-01 09:16:49 +03:00
|
|
|
units/kube-apiserver.service \
|
|
|
|
units/kube-controller-manager.service \
|
|
|
|
units/kube-scheduler.service \
|
|
|
|
configs/kube-scheduler.yaml \
|
|
|
|
configs/kube-apiserver-to-kubelet.yaml \
|
2025-06-03 05:13:21 +03:00
|
|
|
vagrant@controlplane:~/
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2025-06-03 05:13:21 +03:00
|
|
|
The commands in this lab must be run on the `controlplane` machine. Login to
|
|
|
|
the `controlplane` machine using the `ssh` command. Example:
|
2018-05-12 19:54:18 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-06-03 05:13:21 +03:00
|
|
|
ssh vagrant@controlplane
|
2023-11-01 09:16:49 +03:00
|
|
|
```
|
2018-05-12 19:54:18 +03:00
|
|
|
|
2017-08-29 00:19:25 +03:00
|
|
|
## Provision the Kubernetes Control Plane
|
|
|
|
|
2018-05-12 19:54:18 +03:00
|
|
|
Create the Kubernetes configuration directory:
|
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo mkdir -p /etc/kubernetes/config
|
2025-06-12 01:06:04 +03:00
|
|
|
sudo mkdir -p /var/lib/kubernetes
|
2018-05-12 19:54:18 +03:00
|
|
|
```
|
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
### Install the Kubernetes Controller Binaries
|
2017-08-29 00:19:25 +03:00
|
|
|
|
|
|
|
Install the Kubernetes binaries:
|
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2018-05-12 19:54:18 +03:00
|
|
|
{
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo mv kube-apiserver \
|
2023-11-01 09:16:49 +03:00
|
|
|
kube-controller-manager \
|
|
|
|
kube-scheduler kubectl \
|
|
|
|
/usr/local/bin/
|
2018-05-12 19:54:18 +03:00
|
|
|
}
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Configure the Kubernetes API Server
|
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2018-05-12 19:54:18 +03:00
|
|
|
{
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo mv ca.crt ca.key \
|
2025-06-02 06:37:55 +03:00
|
|
|
kube-apiserver.key kube-apiserver.crt \
|
2023-11-01 09:16:49 +03:00
|
|
|
service-accounts.key service-accounts.crt \
|
|
|
|
encryption-config.yaml \
|
|
|
|
/var/lib/kubernetes/
|
2018-05-12 19:54:18 +03:00
|
|
|
}
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
Install the systemd service unit files for `kube-apiserver.service`,
|
|
|
|
`kube-controller-manager.service`, and `kube-scheduler.service`:
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-06-12 01:06:04 +03:00
|
|
|
sudo mv kube-*.service /etc/systemd/system
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
### Configurations Kubernetes Cluster Components
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
Install the `kube-controller-manager` and `kube-scheduler` kubeconfigs:
|
2018-05-12 19:54:18 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-06-12 01:06:04 +03:00
|
|
|
sudo mv kube-*.kubeconfig /var/lib/kubernetes/
|
2018-05-12 19:54:18 +03:00
|
|
|
```
|
|
|
|
|
2017-08-29 00:19:25 +03:00
|
|
|
|
|
|
|
### Configure the Kubernetes Scheduler
|
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
This will set up the static pod scheduler.
|
2018-05-12 19:54:18 +03:00
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
Install the `kube-scheduler.yaml` configuration file:
|
2018-05-12 19:54:18 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo mv kube-scheduler.yaml /etc/kubernetes/config/
|
2018-05-12 19:54:18 +03:00
|
|
|
```
|
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
### Start the Control Plane Components
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2025-06-12 01:06:04 +03:00
|
|
|
These components have been installed as standalone services managed by systemd.
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2018-05-12 19:54:18 +03:00
|
|
|
{
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo systemctl daemon-reload
|
2025-04-07 04:32:30 +03:00
|
|
|
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo systemctl enable kube-apiserver \
|
2023-11-01 09:16:49 +03:00
|
|
|
kube-controller-manager kube-scheduler
|
2025-04-07 04:32:30 +03:00
|
|
|
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo systemctl start kube-apiserver \
|
2023-11-01 09:16:49 +03:00
|
|
|
kube-controller-manager kube-scheduler
|
2018-05-12 19:54:18 +03:00
|
|
|
}
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2018-05-12 19:54:18 +03:00
|
|
|
> Allow up to 10 seconds for the Kubernetes API Server to fully initialize.
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
You can check if any of the control plane components are active using the
|
|
|
|
`systemctl` command. For example, to check if the `kube-apiserver` is fully
|
|
|
|
initialized, and active, run the following command:
|
2025-04-08 03:08:56 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
systemctl is-active kube-apiserver
|
|
|
|
```
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
For a more detailed status check, which includes additional process information
|
|
|
|
and log messages, use the `systemctl status` command:
|
2025-04-08 03:08:56 +03:00
|
|
|
|
|
|
|
```bash
|
2025-06-03 05:13:21 +03:00
|
|
|
sudo systemctl status kube-apiserver
|
|
|
|
sudo systemctl status kube-controller-manager
|
|
|
|
sudo systemctl status kube-scheduler
|
2025-04-08 03:08:56 +03:00
|
|
|
```
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
If you run into any errors, or want to view the logs for any of the control
|
|
|
|
plane components, use the `journalctl` command. For example, to view the logs
|
|
|
|
for the `kube-apiserver` run the following command:
|
2025-04-08 03:08:56 +03:00
|
|
|
|
|
|
|
```bash
|
2025-06-03 16:32:11 +03:00
|
|
|
sudo journalctl -u kube-apiserver
|
2025-04-08 03:08:56 +03:00
|
|
|
```
|
2017-08-29 00:19:25 +03:00
|
|
|
|
|
|
|
### Verification
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
At this point the Kubernetes control plane components should be up and running.
|
|
|
|
Verify this using the `kubectl` command line tool:
|
2025-04-08 03:08:56 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
|
|
|
kubectl cluster-info \
|
|
|
|
--kubeconfig admin.kubeconfig
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```text
|
2021-05-02 08:33:46 +03:00
|
|
|
Kubernetes control plane is running at https://127.0.0.1:6443
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2017-10-02 06:37:09 +03:00
|
|
|
## RBAC for Kubelet Authorization
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
In this section you will configure RBAC permissions to allow the Kubernetes API
|
|
|
|
Server to access the Kubelet API on each worker node. Access to the Kubelet API
|
|
|
|
is required for retrieving metrics, logs, and executing commands in pods.
|
2017-10-02 06:37:09 +03:00
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
> This tutorial sets the Kubelet `--authorization-mode` flag to `Webhook`.
|
|
|
|
> Webhook mode uses the [SubjectAccessReview] API to determine authorization.
|
2017-10-02 06:37:09 +03:00
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
The commands in this section will affect the entire cluster and only need to be
|
|
|
|
run on the `controlplane` machine.
|
2019-09-14 21:41:56 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-06-09 01:21:10 +03:00
|
|
|
ssh vagrant@controlplane
|
2017-10-02 06:37:09 +03:00
|
|
|
```
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
Create the `system:kube-apiserver-to-kubelet` [ClusterRole] with permissions
|
|
|
|
to access the Kubelet API and perform most common tasks associated with
|
|
|
|
managing pods:
|
2017-10-02 06:37:09 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
|
|
|
kubectl apply -f kube-apiserver-to-kubelet.yaml \
|
|
|
|
--kubeconfig admin.kubeconfig
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Verification
|
|
|
|
|
2025-06-03 16:32:11 +03:00
|
|
|
At this point the Kubernetes control plane is up and running. Run the following
|
|
|
|
commands from the `jumpbox` machine to verify it's working:
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2025-06-02 06:37:55 +03:00
|
|
|
Make an HTTP request for the Kubernetes version info:
|
2017-08-29 00:19:25 +03:00
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```bash
|
2025-04-08 17:30:28 +03:00
|
|
|
curl --cacert ca.crt \
|
2025-06-02 05:59:11 +03:00
|
|
|
https://controlplane.kubernetes.local:6443/version
|
2017-08-29 00:19:25 +03:00
|
|
|
```
|
|
|
|
|
2023-11-01 09:16:49 +03:00
|
|
|
```text
|
2017-08-29 00:19:25 +03:00
|
|
|
{
|
|
|
|
"major": "1",
|
2025-04-07 04:32:30 +03:00
|
|
|
"minor": "32",
|
2025-06-03 01:15:47 +03:00
|
|
|
"gitVersion": "v1.33.1",
|
2025-04-07 04:32:30 +03:00
|
|
|
"gitCommit": "32cc146f75aad04beaaa245a7157eb35063a9f99",
|
2017-08-29 00:19:25 +03:00
|
|
|
"gitTreeState": "clean",
|
2025-04-07 04:32:30 +03:00
|
|
|
"buildDate": "2025-03-11T19:52:21Z",
|
|
|
|
"goVersion": "go1.23.6",
|
2017-08-29 00:19:25 +03:00
|
|
|
"compiler": "gc",
|
2023-11-01 09:16:49 +03:00
|
|
|
"platform": "linux/arm64"
|
2017-08-29 00:19:25 +03:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Next: [Bootstrapping the Kubernetes Worker Nodes](09-bootstrapping-kubernetes-workers.md)
|
2025-06-03 16:32:11 +03:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
[SubjectAccessReview]: https://kubernetes.io/docs/reference/access-authn-authz/authorization/#checking-api-access
|
|
|
|
[ClusterRole]: https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole
|