Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thesurlydev/kubernetes-bare-metal

Personal notes for setting up a Kubernetes cluster on bare metal.
https://github.com/thesurlydev/kubernetes-bare-metal

k8s k8s-cluster k8s-cluster-ubuntu kubernetes kubernetes-install

Last synced: 10 days ago
JSON representation

Personal notes for setting up a Kubernetes cluster on bare metal.

Awesome Lists containing this project

README

        

# kubernetes-bare-metal

Kubernetes setup for Ubuntu on bare metal.

The intent is to outline the steps necessary to install a multi-node Kubernetes 1.18 cluster on Ubuntu 18.04.


* [Components](#components)
* [Gotchas](#gotchas)
* [Docker](#docker)
* [Installation](#installation)
* [Post-install configuration](#post-install-configuration)
* [kubectl, kubeadm, kubelet](#kubectl-kubeadm-kubelet)
* [kubelet service config](#kubelet-service-config)
* [Disable Swap](#disable-swap)
* [Install via kubeadm](#install-via-kubeadm)
* [Troubleshooting kubelet](#troubleshooting-kubelet)
* [Post Install](#post-install)
* [Weave](#weave)
* [Join Additional Nodes (workers)](#join-additional-nodes-workers)
* [Dashboard](#dashboard)
* [Create user](#create-user)
* [Install Dashboard](#install-dashboard)
* [Start Dashboard Proxy](#start-dashboard-proxy)
* [Login](#login)
* [Pulling from Private Docker Registries](#pulling-from-private-docker-registries)
* [Updating a deployment](#updating-a-deployment)
* [Get a list of all containers running in all pods in all namespaces](#get-a-list-of-all-containers-running-in-all-pods-in-all-namespaces)
* [Port forwarding](#port-forwarding)
* [Multiple Clusters](#multiple-clusters)
* [Troubleshooting](#troubleshooting)

## Components

* Ubuntu 18.04
* Kubernetes 1.18 with `cgroups-driver=systemd`
* Docker 19.03.11
* Docker Hub Registry
* Weave 2.6.2
* Web UI (kubernetes dashboard)

## Gotchas

* Versions
* Ensuring cgroups-driver for Docker and Kubelet match
* Starting over:
* kubeadm reset
* sudo rm -rf /etc/kubernetes
* Making changes to kubelet:
* systemctl daemon-reload
* systemctl restart kubelet

## Docker

### Installation

First, update existing list of packages:
```
sudo apt update
```

Next, install prerequisites:

```
sudo apt install apt-transport-https ca-certificates curl software-properties-common
```
Add the GPG key for the official Docker repository:
```
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -`
```
Add the Docker repository to APT sources:
```
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
```
Update package database with the Docker packages:
```
sudo apt update
```
Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
```
apt-cache policy docker-ce
```
Now, install:
```
sudo apt install docker-ce
```

Confirm install:
```
sudo systemctl status docker
```
should return somethink like:
```
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-06-19 15:27:09 UTC; 4s ago
Docs: https://docs.docker.com
Main PID: 17823 (dockerd)
Tasks: 22
CGroup: /system.slice/docker.service
└─17823 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
```

```
docker version
```

```bash
Client: Docker Engine - Community
Version: 19.03.11
API version: 1.40
Go version: go1.13.10
Git commit: 42e35e61f3
Built: Mon Jun 1 09:12:22 2020
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.11
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 42e35e61f3
Built: Mon Jun 1 09:10:54 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
```

### Post-install Configuration

Update cgroupdriver in `/etc/docker/daemon.json` to use systemd:
```
{
"exec-opts": [
"native.cgroupdriver=systemd"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
```

Restart Docker daemon via:
```
systemctl restart docker
```

Verify Docker cgroup driver via:
```
docker info -f {{.CgroupDriver}}
```

## kubectl, kubeadm, kubelet

```bash
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat < kgen-service-deployment.yaml
```
Second, edit the file as necessary.

Lastly, update the deployment with your changes:
```bash
kubectl replace deployments kgen-service -f ./kgen-service-deployment.yaml
```
-OR-

Just edit the deployment. When it's saved the deployment will be replaced:

```bash
kubectl edit deployments kgen-service
```

## Get a list of all containers running in all pods in all namespaces

```bash
kubectl get pods --all-namespaces -o jsonpath={..image} | tr -s '[[:space:]]' '\n' | sort -u
```

## Port forwarding

Forward one or more local ports to a pod. This command requires the node to have 'socat' installed.

As an example to port forward to an application listening on port `8080`:

```bash
kubectl port-forward deployment/kgen-service 8080
```

## Multiple Clusters

To view the available contexts/clusters:

```
kubectl config get-contexts
```

To switch from one cluster to another:

```
kubectl config use-context kubernetes-admin@kubernetes
```

## Custom Namespaces

```
kubectl get pods -n
```

## Scaling your deployments

```
kubectl scale deployment --replicas
```

## Zero downtime deployments

The default way to update a running application in Kubernetes is to deploy a new image tag to your Docker registry and then deploy it using:

```
kubectl set image deployment/-app =
```

Using livenessProbes and readinessProbe allows you to tell Kubernetes about the state of your applications, in order to ensure availability of your services. You will need a minimum of 2 replicas for every application if you want to have zero downtime deployment. This is because the rolling upgrade strategy first stops a running replica in order to place a new one. Running only one replica will cause a short downtime during upgrades.

## Troubleshooting

### Deploy Verification

Wait for deploy to complete:
```
kubectl rollout status -n default deployments/springboot-microservice --watch
```
-or-
```
`curl --silent --fail --retry 60 --retry-delay 5 --retry-connrefused --insecure --output /dev/null $ENDPOINT/health`
```