Skip to main content

Kubernetes Cluster Bootstrap

Picture of Bartek Antoniak, null

Bartek Antoniak

Mar 1, 2018|7 min read
Image Alt
Image Alt

Image Alt

1sudo docker run --rm --cap-add=NET_ADMIN --net=host quay.io/coreos/dnsmasq \
2 -d -q \
3 --dhcp-range=192.168.1.3,192.168.1.254 \
4 --enable-tftp --tftp-root=/var/lib/tftpboot \
5 --dhcp-match=set:bios,option:client-arch,0 \
6 --dhcp-boot=tag:bios,undionly.kpxe \
7 --dhcp-match=set:efi32,option:client-arch,6 \
8 --dhcp-boot=tag:efi32,ipxe.efi \
9 --dhcp-match=set:efibc,option:client-arch,7 \
10 --dhcp-boot=tag:efibc,ipxe.efi \
11 --dhcp-match=set:efi64,option:client-arch,9 \
12 --dhcp-boot=tag:efi64,ipxe.efi \
13 --dhcp-userclass=set:ipxe,iPXE \
14 --dhcp-boot=tag:ipxe,http://matchbox.example.com:8080/boot.ipxe \
15 --address=/matchbox.example/192.168.1.2 \
16 --log-queries \
17 --log-dhcp
Image Alt

1---
2systemd:
3 units:
4 - name: docker.service
5 enable: true
6 - name: locksmithd.service
7 mask: true
8 - name: kubelet.path
9 enable: true
10 contents: |
11 [Unit]
12 Description=Watch for kubeconfig
13 [Path]
14 PathExists=/etc/kubernetes/kubeconfig
15 [Install]
16 WantedBy=multi-user.target
17 - name: wait-for-dns.service
18 enable: true
19 contents: |
20 [Unit]
21 Description=Wait for DNS entries
22 Wants=systemd-resolved.service
23 Before=kubelet.service
24 [Service]
25 Type=oneshot
26 RemainAfterExit=true
27 ExecStart=/bin/sh -c 'while ! /usr/bin/grep '^[^#[:space:]]' /etc/resolv.conf > /dev/null; do sleep 1; done'
28 [Install]
29 RequiredBy=kubelet.service
1sudo docker run --rm quay.io/coreos/matchbox:latest \
2 -p 8080:8080 \
3 -v /var/lib/matchbox:/var/lib/matchbox:Z \
4 -address=0.0.0.0:8080 \
5 -log-level=debug
1{
2 "id": "node1",
3 "name": "Worker Node",
4 "profile": "worker",
5 "selector": {
6 "mac": "52:54:00:b2:2f:86"
7 },
8 "metadata": {
9 "domain_name": "node1.example.com",
10 "k8s_dns_service_ip": "10.3.0.10",
11 "pxe": "true",
12 "ssh_authorized_keys": [
13 "ssh-rsa XXXXXXXXXXXX fake-test-key-REMOVE-ME"
14 ]
15 }
16}
1{
2 "id": "worker",
3 "name": "Worker",
4 "boot": {
5 "kernel": "/assets/coreos/1465.8.0/coreos_production_pxe.vmlinuz",
6 "initrd": ["/assets/coreos/1465.8.0/coreos_production_pxe_image.cpio.gz"],
7 "args": [
8 "initrd=coreos_production_pxe_image.cpio.gz",
9 "root=/dev/sda1",
10 "coreos.config.url=http://matchbox.example.com:8080/ignition?uuid=${uuid}&mac=${mac:hexhyp}",
11 "coreos.first_boot=yes",
12 "console=tty0",
13 "console=ttyS0",
14 "coreos.autologin"
15 ]
16 },
17 "ignition_id": "worker.yaml"
18}
1$ tree /var/lib/matchbox/assets
2/var/lib/matchbox/assets/
3├── coreos
4└── 1465.8.0
5├── CoreOS_Image_Signing_Key.asc
6├── coreos_production_image.bin.bz2
7├── coreos_production_image.bin.bz2.sig
8├── coreos_production_pxe_image.cpio.gz
9├── coreos_production_pxe_image.cpio.gz.sig
10├── coreos_production_pxe.vmlinuz
11└── coreos_production_pxe.vmlinuz.sig
1---
2systemd:
3 units:
4 - name: docker.service
5 enable: true
6 - name: locksmithd.service
7 mask: true
8 - name: kubelet.path
9 enable: true
10 contents: |
11 [Unit]
12 Description=Watch for kubeconfig
13 [Path]
14 PathExists=/etc/kubernetes/kubeconfig
15 [Install]
16 WantedBy=multi-user.target
17 - name: wait-for-dns.service
18 enable: true
19 contents: |
20 [Unit]
21 Description=Wait for DNS entries
22 Wants=systemd-resolved.service
23 Before=kubelet.service
24 [Service]
25 Type=oneshot
26 RemainAfterExit=true
27 ExecStart=/bin/sh -c 'while ! /usr/bin/grep '^[^#[:space:]]' /etc/resolv.conf > /dev/null; do sleep 1; done'
28 [Install]
29 RequiredBy=kubelet.service
1- name: kubelet.service
2 command: start
3 runtime: true
4 content: |
5 [Unit]
6 Description=Kubelet via Hyperkube ACI
7
8 [Service]
9Environment=KUBELET_IMAGE=quay.io/coreos/hyperkube:v1.9.2_coreos.0
10 ExecStart=/usr/lib/coreos/kubelet-wrapper \
11 --kubeconfig=/etc/kubernetes/kubelet-kubeconfig.yaml \
12 --require-kubeconfig \
13 --cni-conf-dir=/etc/kubernetes/cni/net.d \
14 --network-plugin=cni \
15 --lock-file=/var/run/lock/kubelet.lock \
16 --exit-on-lock-contention \
17 --pod-manifest-path=/etc/kubernetes/manifests \
18 --allow-privileged \
19 --node-labels="node-role.kubernetes.io/node",type=worker,cluster=baremetal \
20 --cni-bin-dir=/var/lib/cni/bin \
21 --minimum-container-ttl-duration=6m0s \
22 --cluster_dns=10.5.0.10 \
23 --cluster-domain=cluster.local \
24 --client-ca-file=/etc/kubernetes/ssl/ca.pem \
25 --anonymous-auth=false \
26 --register-node=true
27
28 ExecStop=-/usr/bin/rkt stop --uuid-file=/var/cache/kubelet-pod.uuid
29
30 Restart=always
31 RestartSec=10
32
33 [Install]
34 WantedBy=multi-user.target
1{
2 "name": "k8s-pod-network",
3 "type": "calico",
4 "etcd_endpoints": "__ETCD_ENDPOINTS__",
5 "etcd_key_file": "__ETCD_KEY_FILE__",
6 "etcd_cert_file": "__ETCD_CERT_FILE__",
7 "etcd_ca_cert_file": "__ETCD_CA_CERT_FILE__",
8 "log_level": "__LOG_LEVEL__",
9 "ipam": {
10 "type": "calico-ipam"
11 },
12 "policy": {
13 "type": "k8s",
14 "k8s_api_root": "https://__KUBERNETES_SERVICE_HOST__:__KUBERNETES_SERVICE_PORT__",
15 "k8s_auth_token": "__SERVICEACCOUNT_TOKEN__"
16 },
17 "kubernetes": {
18 "kubeconfig": "__KUBECONFIG_FILEPATH__"
19 }
20}
1- path: /etc/kubernetes/manifests/kube-proxy.yaml
2 content: |
3 apiVersion: v1
4 kind: Pod
5 metadata:
6 name: kube-proxy
7 namespace: kube-system
8 labels:
9 k8s-app: kube-proxy
10 spec:
11 containers:
12 - name: kube-proxy
13 image: quay.io/coreos/hyperkube:v1.9.2_coreos.0
14 command:
15 - ./hyperkube
16 - proxy
17 - --kubeconfig=/etc/kubernetes/kubelet-kubeconfig.yaml
18 - --proxy-mode=iptables
19 - --cluster-cidr=10.123.0.0/16
20 securityContext:
21 privileged: true
22 volumeMounts:
23 - mountPath: /etc/ssl/certs
24 name: ssl-certs-host
25 readOnly: true
26 - name: etc-kubernetes
27 mountPath: /etc/kubernetes
28 readOnly: true
29 hostNetwork: true
30 volumes:
31 - hostPath:
32 path: /usr/share/ca-certificates
33 name: ssl-certs-host
34 - name: etc-kubernetes
35 hostPath:
36 path: /etc/kubernetes
Image Alt

Subscribe to our newsletter and never miss an article