https://github.com/jaypyles/kubernetes-starter
Create a very basic kubernetes cluster in Virtualbox using Ansible.
https://github.com/jaypyles/kubernetes-starter
Last synced: about 2 months ago
JSON representation
Create a very basic kubernetes cluster in Virtualbox using Ansible.
- Host: GitHub
- URL: https://github.com/jaypyles/kubernetes-starter
- Owner: jaypyles
- Created: 2024-09-14T19:33:55.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-18T02:38:29.000Z (over 1 year ago)
- Last Synced: 2025-03-22T19:29:21.663Z (about 1 year ago)
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Summary
## Startup
- Create two virtual machines using VirtualBox, using a host-only network adapter configuration
- Enable the DHCP server on the host only network
- `sudo systemctl restart networking && sudo dhclient` to assign an address using dhcp
## Creating a Cluster
### Master Node
- Disable swap
```bash
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
```
- Init the cluster
```bash
sudo kubeadm init --apiserver-advertise-address= --pod-network-cidr=192.168.0.0/16
```
- Apply a network configuration
```bash
# apply flannel network config
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
```
- Get the join token
```bash
kubeadm token create --print-join-command
```
### Worker Node
- Join cluster
```bash
#join the cluster
sudo kubeadm join --token --discovery-token-ca-cert-hash
```
## Troubleshooting
Using Debian 11 or Ubuntu 22.04, the following steps are required to enable systemd cgroup
```bash
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
sudo service containerd restart
sudo service kubelet restart
```
This is done manually for now to avoid cert errors:
```bash
sudo rm -rf $HOME/.kube || true
sudo mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```
# K3S setup
Install k3s
```bash
curl -sfL https://get.k3s.io | sh -
```
Get join token
```bash
cat /etc/rancher/k3s/k3s.yaml
```
Join the cluster on the worker node
```bash
export URL="https://:6443"
export TOKEN="<>"
curl -sfL https://get.k3s.io | K3S_URL=$URL K3S_TOKEN=$TOKEN sh -
```