| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | minimumLimaVersion: 2.0.0 |
| 25 | |
| 26 | base: template:_images/ubuntu-lts |
| 27 | |
| 28 | |
| 29 | mounts: [] |
| 30 | containerd: |
| 31 | system: true |
| 32 | user: false |
| 33 | provision: |
| 34 | |
| 35 | - mode: system |
| 36 | script: | |
| 37 | #!/bin/bash |
| 38 | set -eux -o pipefail |
| 39 | command -v kubeadm >/dev/null 2>&1 && exit 0 |
| 40 | # Install and configure prerequisites |
| 41 | cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf |
| 42 | overlay |
| 43 | br_netfilter |
| 44 | EOF |
| 45 | modprobe overlay |
| 46 | modprobe br_netfilter |
| 47 | cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf |
| 48 | net.bridge.bridge-nf-call-iptables = 1 |
| 49 | net.ipv4.ip_forward = 1 |
| 50 | net.bridge.bridge-nf-call-ip6tables = 1 |
| 51 | EOF |
| 52 | sysctl --system |
| 53 | # Installing kubeadm, kubelet and kubectl |
| 54 | export DEBIAN_FRONTEND=noninteractive |
| 55 | apt-get update |
| 56 | apt-get install -y --no-upgrade ca-certificates curl gnupg |
| 57 | STABILITY="{{.Param.stability}}" |
| 58 | {{if eq .Param.release "stable" }} |
| 59 | RELEASE=$(curl -L -s https://dl.k8s.io/release/stable.txt | cut -d'.' -f1-2) |
| 60 | {{else}} |
| 61 | RELEASE="{{.Param.release}}" |
| 62 | {{end}} |
| 63 | {{- if .Param.proxy }} |
| 64 | echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] {{.Param.proxy}}/HTTPS///pkgs.k8s.io/core:/${STABILITY}:/${RELEASE}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list |
| 65 | {{- else}} |
| 66 | echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/${STABILITY}:/${RELEASE}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list |
| 67 | {{- end}} |
| 68 | curl -fsSL https://pkgs.k8s.io/core:/${STABILITY}:/${RELEASE}/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg |
| 69 | apt-get update |
| 70 | apt-get install -y kubelet kubeadm kubectl && apt-mark hold kubelet kubeadm kubectl |
| 71 | systemctl enable --now kubelet |
| 72 | |
| 73 | - mode: system |
| 74 | script: | |
| 75 | #!/bin/bash |
| 76 | set -eux -o pipefail |
| 77 | [ -e /etc/containerd/conf.d/k8s.toml ] && exit 0 |
| 78 | mkdir -p /etc/containerd/conf.d |
| 79 | # Configuring the systemd cgroup driver |
| 80 | # Overriding the sandbox (pause) image |
| 81 | cat <<EOF >/etc/containerd/conf.d/k8s.toml |
| 82 | version = 2 |
| 83 | [plugins] |
| 84 | [plugins."io.containerd.grpc.v1.cri"] |
| 85 | sandbox_image = "$(kubeadm config images list | grep pause | sort -r | head -n1)" |
| 86 | [plugins."io.containerd.grpc.v1.cri".containerd] |
| 87 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes] |
| 88 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] |
| 89 | runtime_type = "io.containerd.runc.v2" |
| 90 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] |
| 91 | SystemdCgroup = true |
| 92 | {{- if .Param.mirror }} |
| 93 | [plugins."io.containerd.grpc.v1.cri".registry] |
| 94 | config_path = "/etc/containerd/certs.d" |
| 95 | {{- end}} |
| 96 | [plugins."io.containerd.cri.v1.runtime".cni] |
| 97 | bin_dirs = ["/usr/local/libexec/cni","/opt/cni/bin"] |
| 98 | EOF |
| 99 | {{if .Param.mirror }} |
| 100 | mkdir -p /etc/containerd/certs.d/_default |
| 101 | cat <<EOF >/etc/containerd/certs.d/_default/hosts.toml |
| 102 | [host."{{.Param.mirror}}"] |
| 103 | capabilities = ["pull", "resolve"] |
| 104 | EOF |
| 105 | {{end}} |
| 106 | systemctl restart containerd |
| 107 | |
| 108 | - mode: system |
| 109 | script: | |
| 110 | #!/bin/bash |
| 111 | set -eux -o pipefail |
| 112 | test -e /etc/kubernetes/admin.conf && exit 0 |
| 113 | export KUBECONFIG=/etc/kubernetes/admin.conf |
| 114 | {{if not ( and .Param.url .Param.token )}} |
| 115 | systemctl stop kubelet |
| 116 | VERSION="{{.Param.version}}" |
| 117 | kubeadm config images list --kubernetes-version="${VERSION}" |
| 118 | kubeadm config images pull --kubernetes-version="${VERSION}" --cri-socket=unix:///run/containerd/containerd.sock |
| 119 | systemctl start kubelet |
| 120 | # Initializing your control-plane node |
| 121 | cat <<EOF >/etc/kubeadm-config.yaml |
| 122 | kind: InitConfiguration |
| 123 | apiVersion: kubeadm.k8s.io/v1beta4 |
| 124 | nodeRegistration: |
| 125 | criSocket: unix:///run/containerd/containerd.sock |
| 126 | --- |
| 127 | kind: ClusterConfiguration |
| 128 | apiVersion: kubeadm.k8s.io/v1beta4 |
| 129 | kubernetesVersion: "${VERSION}" |
| 130 | apiServer: |
| 131 | certSANs: # --apiserver-cert-extra-sans |
| 132 | - "127.0.0.1" |
| 133 | networking: |
| 134 | podSubnet: "10.244.0.0/16" # --pod-network-cidr |
| 135 | --- |
| 136 | kind: KubeletConfiguration |
| 137 | apiVersion: kubelet.config.k8s.io/v1beta1 |
| 138 | cgroupDriver: systemd |
| 139 | EOF |
| 140 | kubeadm init --config /etc/kubeadm-config.yaml |
| 141 | {{else}} |
| 142 | cat <<EOF >/etc/kubeadm-config.yaml |
| 143 | kind: JoinConfiguration |
| 144 | apiVersion: kubeadm.k8s.io/v1beta4 |
| 145 | nodeRegistration: |
| 146 | criSocket: unix:///run/containerd/containerd.sock |
| 147 | discovery: |
| 148 | bootstrapToken: |
| 149 | apiServerEndpoint: "{{.Param.url}}" |
| 150 | token: "{{.Param.token}}" |
| 151 | caCertHashes: |
| 152 | - "{{.Param.discoveryTokenCaCertHash}}" |
| 153 | EOF |
| 154 | kubeadm join --config /etc/kubeadm-config.yaml |
| 155 | {{end}} |
| 156 | |
| 157 | {{if not ( and .Param.url .Param.token )}} |
| 158 | |
| 159 | {{if eq .Param.flannelVersion "latest" }} |
| 160 | kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml |
| 161 | {{else}} |
| 162 | kubectl apply -f https://github.com/flannel-io/flannel/releases/download/{{.Param.flannelVersion}}/kube-flannel.yml |
| 163 | {{end}} |
| 164 | |
| 165 | kubectl taint nodes --all node-role.kubernetes.io/control-plane- |
| 166 | |
| 167 | mkdir -p /root/.kube && ln -sf $KUBECONFIG /root/.kube/config |
| 168 | |
| 169 | |
| 170 | |
| 171 | sed -e "/server:/ s|https://.*:\([0-9]*\)$|https://127.0.0.1:\1|" $KUBECONFIG >/root/.kube/config.localhost |
| 172 | {{end}} |
| 173 | - mode: system |
| 174 | script: | |
| 175 | #!/bin/bash |
| 176 | set -eux -o pipefail |
| 177 | # set up user config on control plane node |
| 178 | {{if not ( and .Param.url .Param.token )}} |
| 179 | export KUBECONFIG=/etc/kubernetes/admin.conf |
| 180 | mkdir -p {{.Home}}/.kube |
| 181 | cp -f $KUBECONFIG {{.Home}}/.kube/config |
| 182 | chown -R {{.User}} {{.Home}}/.kube |
| 183 | {{end}} |
| 184 | probes: |
| 185 | - description: "kubeadm to be installed" |
| 186 | script: | |
| 187 | #!/bin/bash |
| 188 | set -eux -o pipefail |
| 189 | if ! timeout 30s bash -c "until command -v kubeadm >/dev/null 2>&1; do sleep 3; done"; then |
| 190 | echo >&2 "kubeadm is not installed yet" |
| 191 | exit 1 |
| 192 | fi |
| 193 | hint: | |
| 194 | See "/var/log/cloud-init-output.log" in the guest |
| 195 | - description: "kubernetes images to be pulled" |
| 196 | script: | |
| 197 | #!/bin/bash |
| 198 | set -eux -o pipefail |
| 199 | {{if not ( and .Param.url .Param.token )}} |
| 200 | if ! timeout 30s bash -c "images=\"$(kubeadm config images list)\"; until for image in \$images; do sudo ctr -n k8s.io image inspect \$image >/dev/null; done; do sleep 3; done"; then |
| 201 | echo >&2 "k8s images are not pulled yet" |
| 202 | exit 1 |
| 203 | fi |
| 204 | {{end}} |
| 205 | - description: "kubeadm to be completed" |
| 206 | script: | |
| 207 | #!/bin/bash |
| 208 | set -eux -o pipefail |
| 209 | {{if not ( and .Param.url .Param.token )}} |
| 210 | if ! timeout 300s bash -c "until test -f /etc/kubernetes/admin.conf; do sleep 3; done"; then |
| 211 | echo >&2 "k8s is not running yet" |
| 212 | exit 1 |
| 213 | fi |
| 214 | {{end}} |
| 215 | hint: | |
| 216 | The k8s kubeconfig file has not yet been created. |
| 217 | - description: "kubernetes cluster to be running" |
| 218 | script: | |
| 219 | #!/bin/bash |
| 220 | set -eux -o pipefail |
| 221 | {{if not ( and .Param.url .Param.token )}} |
| 222 | if ! timeout 300s bash -c "until kubectl version >/dev/null 2>&1; do sleep 3; done"; then |
| 223 | echo >&2 "kubernetes cluster is not up and running yet" |
| 224 | exit 1 |
| 225 | fi |
| 226 | {{end}} |
| 227 | - description: "coredns deployment to be running" |
| 228 | script: | |
| 229 | #!/bin/bash |
| 230 | set -eux -o pipefail |
| 231 | {{if not ( and .Param.url .Param.token )}} |
| 232 | kubectl wait -n kube-system --timeout=180s --for=condition=available deploy coredns |
| 233 | {{end}} |
| 234 | copyToHost: |
| 235 | - guest: "/root/.kube/config.localhost" |
| 236 | host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml" |
| 237 | skipIfMissing: true |
| 238 | deleteOnStop: true |
| 239 | message: | |
| 240 | {{- if not ( and .Param.url .Param.token )}} |
| 241 | To run `kubectl` on the host (assumes kubectl is installed), run the following commands: |
| 242 | ------ |
| 243 | export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml" |
| 244 | kubectl ... |
| 245 | ------ |
| 246 | {{end -}} |
| 247 | param: |
| 248 | |
| 249 | |
| 250 | proxy: "" |
| 251 | |
| 252 | |
| 253 | mirror: "" |
| 254 | |
| 255 | |
| 256 | stability: "stable" |
| 257 | |
| 258 | |
| 259 | release: "v1.37" |
| 260 | |
| 261 | version: "stable" |
| 262 | |
| 263 | flannelVersion: "v0.28.9" |
| 264 | url: "" |
| 265 | token: "" |
| 266 | discoveryTokenCaCertHash: "" |