Adapt controllers bootstrap, replace GCP LB by Nginx LB (Nginx can handle HTTPS healthcheck), change IP
parent
318431cbc5
commit
b6360c7944
|
@ -1,13 +1,13 @@
|
||||||
# Bootstrapping the Kubernetes Control Plane
|
# Bootstrapping the Kubernetes Control Plane
|
||||||
|
|
||||||
In this lab you will bootstrap the Kubernetes control plane across three compute instances and configure it for high availability. You will also create an external load balancer that exposes the Kubernetes API Servers to remote clients. The following components will be installed on each node: Kubernetes API Server, Scheduler, and Controller Manager.
|
In this lab you will bootstrap the Kubernetes control plane across three VM instances and configure it for high availability. You will also create a load balancer that exposes the Kubernetes API Servers to remote clients. The following components will be installed on each node: Kubernetes API Server, Scheduler, and Controller Manager.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
The commands in this lab must be run on each controller instance: `controller-0`, `controller-1`, and `controller-2`. Login to each controller instance using the `gcloud` command. Example:
|
The commands in this lab must be run on each controller instance: `controller-0`, `controller-1`, and `controller-2`. Login to each controller instance using the `ssh` command. Example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gcloud compute ssh controller-0
|
ssh controller-0
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running commands in parallel with tmux
|
### Running commands in parallel with tmux
|
||||||
|
@ -37,31 +37,28 @@ wget -q --show-progress --https-only --timestamping \
|
||||||
Install the Kubernetes binaries:
|
Install the Kubernetes binaries:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
{
|
chmod +x kube-apiserver kube-controller-manager kube-scheduler kubectl
|
||||||
chmod +x kube-apiserver kube-controller-manager kube-scheduler kubectl
|
sudo mv kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/local/bin/
|
||||||
sudo mv kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/local/bin/
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configure the Kubernetes API Server
|
### Configure the Kubernetes API Server
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
{
|
sudo mkdir -p /var/lib/kubernetes/
|
||||||
sudo mkdir -p /var/lib/kubernetes/
|
|
||||||
|
|
||||||
sudo mv ca.pem ca-key.pem kubernetes-key.pem kubernetes.pem \
|
sudo mv ca.pem ca-key.pem kubernetes-key.pem kubernetes.pem \
|
||||||
service-account-key.pem service-account.pem \
|
service-account-key.pem service-account.pem \
|
||||||
encryption-config.yaml /var/lib/kubernetes/
|
encryption-config.yaml /var/lib/kubernetes/
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The instance internal IP address will be used to advertise the API Server to members of the cluster. Retrieve the internal IP address for the current compute instance:
|
The instance internal IP address will be used to advertise the API Server to members of the cluster. Define the INTERNAL_IP (replace MY_NODE_INTERNAL_IP by the value):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
INTERNAL_IP=$(curl -s -H "Metadata-Flavor: Google" \
|
INTERNAL_IP=MY_NODE_INTERNAL_IP
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> Example for controller-0 : 192.168.8.10
|
||||||
|
|
||||||
Create the `kube-apiserver.service` systemd unit file:
|
Create the `kube-apiserver.service` systemd unit file:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -86,7 +83,7 @@ ExecStart=/usr/local/bin/kube-apiserver \\
|
||||||
--etcd-cafile=/var/lib/kubernetes/ca.pem \\
|
--etcd-cafile=/var/lib/kubernetes/ca.pem \\
|
||||||
--etcd-certfile=/var/lib/kubernetes/kubernetes.pem \\
|
--etcd-certfile=/var/lib/kubernetes/kubernetes.pem \\
|
||||||
--etcd-keyfile=/var/lib/kubernetes/kubernetes-key.pem \\
|
--etcd-keyfile=/var/lib/kubernetes/kubernetes-key.pem \\
|
||||||
--etcd-servers=https://10.240.0.10:2379,https://10.240.0.11:2379,https://10.240.0.12:2379 \\
|
--etcd-servers=https://192.168.8.10:2379,https://192.168.8.11:2379,https://192.168.8.12:2379 \\
|
||||||
--event-ttl=1h \\
|
--event-ttl=1h \\
|
||||||
--encryption-provider-config=/var/lib/kubernetes/encryption-config.yaml \\
|
--encryption-provider-config=/var/lib/kubernetes/encryption-config.yaml \\
|
||||||
--kubelet-certificate-authority=/var/lib/kubernetes/ca.pem \\
|
--kubelet-certificate-authority=/var/lib/kubernetes/ca.pem \\
|
||||||
|
@ -190,59 +187,13 @@ EOF
|
||||||
### Start the Controller Services
|
### Start the Controller Services
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
{
|
sudo systemctl daemon-reload
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl enable kube-apiserver kube-controller-manager kube-scheduler
|
||||||
sudo systemctl enable kube-apiserver kube-controller-manager kube-scheduler
|
sudo systemctl start kube-apiserver kube-controller-manager kube-scheduler
|
||||||
sudo systemctl start kube-apiserver kube-controller-manager kube-scheduler
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
> Allow up to 10 seconds for the Kubernetes API Server to fully initialize.
|
> Allow up to 10 seconds for the Kubernetes API Server to fully initialize.
|
||||||
|
|
||||||
### Enable HTTP Health Checks
|
|
||||||
|
|
||||||
A [Google Network Load Balancer](https://cloud.google.com/compute/docs/load-balancing/network) will be used to distribute traffic across the three API servers and allow each API server to terminate TLS connections and validate client certificates. The network load balancer only supports HTTP health checks which means the HTTPS endpoint exposed by the API server cannot be used. As a workaround the nginx webserver can be used to proxy HTTP health checks. In this section nginx will be installed and configured to accept HTTP health checks on port `80` and proxy the connections to the API server on `https://127.0.0.1:6443/healthz`.
|
|
||||||
|
|
||||||
> The `/healthz` API server endpoint does not require authentication by default.
|
|
||||||
|
|
||||||
Install a basic web server to handle HTTP health checks:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cat > kubernetes.default.svc.cluster.local <<EOF
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name kubernetes.default.svc.cluster.local;
|
|
||||||
|
|
||||||
location /healthz {
|
|
||||||
proxy_pass https://127.0.0.1:6443/healthz;
|
|
||||||
proxy_ssl_trusted_certificate /var/lib/kubernetes/ca.pem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
{
|
|
||||||
sudo mv kubernetes.default.svc.cluster.local \
|
|
||||||
/etc/nginx/sites-available/kubernetes.default.svc.cluster.local
|
|
||||||
|
|
||||||
sudo ln -s /etc/nginx/sites-available/kubernetes.default.svc.cluster.local /etc/nginx/sites-enabled/
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo systemctl restart nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo systemctl enable nginx
|
|
||||||
```
|
|
||||||
|
|
||||||
### Verification
|
### Verification
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -287,7 +238,7 @@ In this section you will configure RBAC permissions to allow the Kubernetes API
|
||||||
The commands in this section will effect the entire cluster and only need to be run once from one of the controller nodes.
|
The commands in this section will effect the entire cluster and only need to be run once from one of the controller nodes.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gcloud compute ssh controller-0
|
ssh controller-0
|
||||||
```
|
```
|
||||||
|
|
||||||
Create the `system:kube-apiserver-to-kubelet` [ClusterRole](https://kubernetes.io/docs/admin/authorization/rbac/#role-and-clusterrole) with permissions to access the Kubelet API and perform most common tasks associated with managing pods:
|
Create the `system:kube-apiserver-to-kubelet` [ClusterRole](https://kubernetes.io/docs/admin/authorization/rbac/#role-and-clusterrole) with permissions to access the Kubelet API and perform most common tasks associated with managing pods:
|
||||||
|
@ -340,54 +291,54 @@ EOF
|
||||||
|
|
||||||
## The Kubernetes Frontend Load Balancer
|
## The Kubernetes Frontend Load Balancer
|
||||||
|
|
||||||
In this section you will provision an external load balancer to front the Kubernetes API Servers. The `kubernetes-the-hard-way` static IP address will be attached to the resulting load balancer.
|
In this section you will provision an Nginx load balancer to front the Kubernetes API Servers. The load balancer will listen on the public IP address (on the `gateway-01` VM).
|
||||||
|
|
||||||
> The compute instances created in this tutorial will not have permission to complete this section. **Run the following commands from the same machine used to create the compute instances**.
|
### Provision an Nginx Load Balancer
|
||||||
|
|
||||||
### Provision a Network Load Balancer
|
Install the Nginx Load Balancer:
|
||||||
|
|
||||||
Create the external load balancer network resources:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
{
|
sudo apt-get update
|
||||||
KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes-the-hard-way \
|
sudo apt-get install -y nginx
|
||||||
--region $(gcloud config get-value compute/region) \
|
|
||||||
--format 'value(address)')
|
|
||||||
|
|
||||||
gcloud compute http-health-checks create kubernetes \
|
|
||||||
--description "Kubernetes Health Check" \
|
|
||||||
--host "kubernetes.default.svc.cluster.local" \
|
|
||||||
--request-path "/healthz"
|
|
||||||
|
|
||||||
gcloud compute firewall-rules create kubernetes-the-hard-way-allow-health-check \
|
|
||||||
--network kubernetes-the-hard-way \
|
|
||||||
--source-ranges 209.85.152.0/22,209.85.204.0/22,35.191.0.0/16 \
|
|
||||||
--allow tcp
|
|
||||||
|
|
||||||
gcloud compute target-pools create kubernetes-target-pool \
|
|
||||||
--http-health-check kubernetes
|
|
||||||
|
|
||||||
gcloud compute target-pools add-instances kubernetes-target-pool \
|
|
||||||
--instances controller-0,controller-1,controller-2
|
|
||||||
|
|
||||||
gcloud compute forwarding-rules create kubernetes-forwarding-rule \
|
|
||||||
--address ${KUBERNETES_PUBLIC_ADDRESS} \
|
|
||||||
--ports 6443 \
|
|
||||||
--region $(gcloud config get-value compute/region) \
|
|
||||||
--target-pool kubernetes-target-pool
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### LB Verification
|
Create the Nginx load balancer network configuration:
|
||||||
|
|
||||||
> The compute instances created in this tutorial will not have permission to complete this section. **Run the following commands from the same machine used to create the compute instances**.
|
|
||||||
|
|
||||||
Retrieve the `kubernetes-the-hard-way` static IP address:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes-the-hard-way \
|
cat <<EOF >> /etc/nginx/nginx.conf
|
||||||
--region $(gcloud config get-value compute/region) \
|
stream {
|
||||||
--format 'value(address)')
|
upstream controller_backend {
|
||||||
|
server 192.168.8.10:6443;
|
||||||
|
server 192.168.8.11:6443;
|
||||||
|
server 192.168.8.12:6443;
|
||||||
|
}
|
||||||
|
server {
|
||||||
|
listen 6443;
|
||||||
|
proxy_pass controller_backend;
|
||||||
|
health_check;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
Restart the service:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl restart nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable the service:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
### Load Balancer Verification
|
||||||
|
|
||||||
|
Define the static public IP address (replace MY_PUBLIC_IP_ADDRESS with your public IP address on the `gateway-01` VM):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
KUBERNETES_PUBLIC_ADDRESS=MY_PUBLIC_IP_ADDRESS
|
||||||
```
|
```
|
||||||
|
|
||||||
Make a HTTP request for the Kubernetes version info:
|
Make a HTTP request for the Kubernetes version info:
|
||||||
|
|
Loading…
Reference in New Issue