Skip to content

Instantly share code, notes, and snippets.

@ypelud
Last active January 30, 2024 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ypelud/f16115b678606a9ea41cfdb869a1e39e to your computer and use it in GitHub Desktop.
Save ypelud/f16115b678606a9ea41cfdb869a1e39e to your computer and use it in GitHub Desktop.

Multipass + kubernetes + calico (mono node)

Get cloud-init file

wget https://gist.github.com/ypelud/f16115b678606a9ea41cfdb869a1e39e/raw/master-cloud-init.yaml

Launch multipass

multipass launch -n master --cloud-init master-cloud-init.yaml -c 2 -m 4G

You can take a smaller vm but be careful with kubeadm

multipass launch -n master --cloud-init master-cloud-init.yaml

Connect to the vm

multipass shell master

Install kubernetes

I have chosen 10.1.0.0/16 cidr because multipass use 192.168.xx.xx, so...

sudo kubeadm init --pod-network-cidr=10.1.0.0/16

If you have chosen smaller vm you must ignore some pre-flight checks

sudo kubeadm init --pod-network-cidr=10.1.0.0/16 --ignore-preflight-errors=NumCPU  --ignore-preflight-errors=Mem

Configure kubeconfig

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Install Calico

Calico official installation

  1. Install operator

    kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
  2. Install component

    kubectl create -f- <<EOF
    apiVersion: operator.tigera.io/v1
    kind: Installation
    metadata:
      name: default
    spec:
      # Configures Calico networking.
      calicoNetwork:
        # Note: The ipPools section cannot be modified post-install.
        ipPools:
        - blockSize: 26
          cidr: 10.1.0.0/16
          encapsulation: VXLANCrossSubnet
          natOutgoing: Enabled
          nodeSelector: all()
    ---
    apiVersion: operator.tigera.io/v1
    kind: APIServer
    metadata:
      name: default
    spec: {}
    EOF
  3. Wait until each pod has the STATUS of Running

    watch kubectl get pods -n calico-system
  4. Allow control plane to schedule pod

    kubectl taint nodes --all node-role.kubernetes.io/master-
  5. Wait until master node has the STATUS of Ready

    kubectl get nodes -o wide
# Originally from here : https://gist.github.com/ngaffa/15d46c98dd82620c8120ddf7398d6dbd
#cloud-config
package_update: true
package_upgrade: true
packages:
# Update the apt package index and install packages needed to use the Docker and Kubernetes apt repositories over HTTPS
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
# Let iptables see bridged traffic
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#letting-iptables-see-bridged-traffic
write_files:
- path: /etc/modules-load.d/k8s.conf
content: |
br_netfilter
- path: /etc/sysctl.d/k8s.conf
content: |
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
# Containerd
# https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd
- path: /etc/modules-load.d/containerd.conf
content: |
overlay
br_netfilter
# Setup required sysctl params, these persist across reboots.
- path: /etc/sysctl.d/99-kubernetes-cri.conf
content: |
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
- path: /etc/docker/daemon.json
content: |
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
# create the docker group
groups:
- docker
# Add default auto created user to docker group
system_info:
default_user:
groups: [docker]
runcmd:
- modprobe br_netfilter # Load br_netfilter module.
- modprobe overlay
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # Add Docker’s official GPG key
- echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # set up the stable repository
- curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg # Download the Google Cloud public signing key:
- echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list # Add the Kubernetes apt repository
- apt-get update -y # Update apt package index
- apt-get install -y docker-ce docker-ce-cli containerd.io kubelet kubeadm kubectl # Install Docker Engine, kubelet, kubeadm and kubectl
- apt-mark hold kubelet kubeadm kubectl # pin kubelet kubeadm kubectl version
- sysctl --system # Reload settings from all system configuration files to take iptables configuration
- mkdir -p /etc/containerd
- containerd config default | sudo tee /etc/containerd/config.toml
- sed -i -e "s/runc\.options\]/runc\.options\]\n SystemdCgroup = true/" /etc/containerd/config.toml
- systemctl restart containerd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment