Skip to content

Instantly share code, notes, and snippets.

@manics
Last active June 21, 2021 14:40
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save manics/dd44bdd78f9cc51270f8d159a5deaa87 to your computer and use it in GitHub Desktop.
Save manics/dd44bdd78f9cc51270f8d159a5deaa87 to your computer and use it in GitHub Desktop.
Setup a single node Kubernetes cluster for development using kubeadm

kubeadm cloudinit

Setup a single node Kubernetes cluster for development using kubeadm: https://kubernetes.io/docs/setup/independent/install-kubeadm/

Create a CentOS 7 or Ubuntu Xenial (16.04) machine, and run kubeadm.sh as root.

You can pass this script as user-data to cloud-init so that it will be automatically run. For example, on openstack:

openstack server create NAME --flavor FLAVOR --key-name KEY --image 'Ubuntu Xenial' --network NET --security-group SECGROUP --user-data kubeadm.sh

openstack server add floating ip VM-NAME 1.2.3.4

Follow /var/log/cloud-init-output.log to see the progress of the script

#!/bin/bash
set -x
if [ -f /etc/debian_version ]; then
apt-get update
apt-get upgrade -y
apt-get install -y apt-transport-https docker.io
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
fi
if [ -f /etc/redhat-release ]; then
yum upgrade -y
yum install -y docker
systemctl enable docker
systemctl start docker
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet
fi
kubeadm init --pod-network-cidr=10.244.0.0/16
kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
kubectl --kubeconfig=/etc/kubernetes/admin.conf taint nodes --all node-role.kubernetes.io/master-kubectl taint nodes --all node-role.kubernetes.io/master-
install -o 1000 -d /home/$(id -nu 1000)/.kube
install -o 1000 /etc/kubernetes/admin.conf /home/$(id -nu 1000)/.kube/config
@David-V-Spencer
Copy link

David-V-Spencer commented May 1, 2019

So I might be mistaken but if the script is run as root then:
install -o 1000 -d /home/$(id -nu 1000)/.kube
install -o 1000 /etc/kubernetes/admin.conf /home/$(id -nu 1000)/.kube/config

Would just be installed as root for users with sudo or root access?

Couldn't this be generalize for all users by adding the kubectl config file to the skel files to be setup for all users on the system?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment