kubernetes-the-hard-way/docs/08-bootstrapping-kubernetes...

207 lines
5.2 KiB
Markdown
Raw Normal View History

2017-08-29 00:19:25 +03:00
# Bootstrapping the Kubernetes Control Plane
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
Connect to the `jumpbox` and copy Kubernetes binaries and systemd unit files
to the `controlplane` machine:
2017-08-29 00:19:25 +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 \
units/kube-apiserver.service \
units/kube-controller-manager.service \
units/kube-scheduler.service \
configs/kube-scheduler.yaml \
configs/kube-apiserver-to-kubelet.yaml \
vagrant@controlplane:~/
2017-08-29 00:19:25 +03:00
```
The commands in this lab must be run on the `controlplane` machine. Login to
the `controlplane` machine using the `ssh` command. Example:
```bash
ssh vagrant@controlplane
```
2017-08-29 00:19:25 +03:00
## Provision the Kubernetes Control Plane
Create the Kubernetes configuration directory:
```bash
sudo mkdir -p /etc/kubernetes/config
sudo mkdir -p /var/lib/kubernetes
```
### Install the Kubernetes Controller Binaries
2017-08-29 00:19:25 +03:00
Install the Kubernetes binaries:
```bash
{
sudo mv kube-apiserver \
kube-controller-manager \
kube-scheduler kubectl \
/usr/local/bin/
}
2017-08-29 00:19:25 +03:00
```
### Configure the Kubernetes API Server
```bash
{
sudo mv ca.crt ca.key \
kube-apiserver.key kube-apiserver.crt \
service-accounts.key service-accounts.crt \
encryption-config.yaml \
/var/lib/kubernetes/
}
2017-08-29 00:19:25 +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
```bash
sudo mv kube-*.service /etc/systemd/system
2017-08-29 00:19:25 +03:00
```
### Configurations Kubernetes Cluster Components
2017-08-29 00:19:25 +03:00
Install the `kube-controller-manager` and `kube-scheduler` kubeconfigs:
```bash
sudo mv kube-*.kubeconfig /var/lib/kubernetes/
```
2017-08-29 00:19:25 +03:00
### Configure the Kubernetes Scheduler
This will set up the static pod scheduler.
Install the `kube-scheduler.yaml` configuration file:
```bash
sudo mv kube-scheduler.yaml /etc/kubernetes/config/
```
### Start the Control Plane Components
2017-08-29 00:19:25 +03:00
These components have been installed as standalone services managed by systemd.
2017-08-29 00:19:25 +03:00
```bash
{
sudo systemctl daemon-reload
2025-04-07 04:32:30 +03:00
sudo systemctl enable kube-apiserver \
kube-controller-manager kube-scheduler
2025-04-07 04:32:30 +03:00
sudo systemctl start kube-apiserver \
kube-controller-manager kube-scheduler
}
2017-08-29 00:19:25 +03:00
```
> Allow up to 10 seconds for the Kubernetes API Server to fully initialize.
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
```
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
sudo systemctl status kube-apiserver
sudo systemctl status kube-controller-manager
sudo systemctl status kube-scheduler
2025-04-08 03:08:56 +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
sudo journalctl -u kube-apiserver
2025-04-08 03:08:56 +03:00
```
2017-08-29 00:19:25 +03:00
### Verification
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
```bash
kubectl cluster-info \
--kubeconfig admin.kubeconfig
2017-08-29 00:19:25 +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
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
> 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
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
```bash
ssh vagrant@controlplane
2017-10-02 06:37:09 +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
```bash
kubectl apply -f kube-apiserver-to-kubelet.yaml \
--kubeconfig admin.kubeconfig
2017-08-29 00:19:25 +03:00
```
### Verification
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
Make an HTTP request for the Kubernetes version info:
2017-08-29 00:19:25 +03:00
```bash
curl --cacert ca.crt \
https://controlplane.kubernetes.local:6443/version
2017-08-29 00:19:25 +03:00
```
```text
2017-08-29 00:19:25 +03:00
{
"major": "1",
2025-04-07 04:32:30 +03:00
"minor": "32",
"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",
"platform": "linux/arm64"
2017-08-29 00:19:25 +03:00
}
```
Next: [Bootstrapping the Kubernetes Worker Nodes](09-bootstrapping-kubernetes-workers.md)
---
[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