Skip to content

Instantly share code, notes, and snippets.

@samloh84
Forked from hunter/install-master.md
Created July 27, 2018 06:57
Show Gist options
  • Select an option

  • Save samloh84/eb6006239c62be47d6f5818563790dc5 to your computer and use it in GitHub Desktop.

Select an option

Save samloh84/eb6006239c62be47d6f5818563790dc5 to your computer and use it in GitHub Desktop.
Install Kube on CoreOS

Install Kubernetes Master

Master:

On the Master run the following commands. They will install the prereqs for Kubernetes

sudo su -

# Enable Docker
systemctl enable docker && systemctl start docker

# Install Networking Plugins
CNI_VERSION="v0.7.1"
mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz

# Install Container Runtime
CRI_VERSION="v1.11.1"
mkdir -p /opt/bin
curl -L "https://github.com/kubernetes-incubator/cri-tools/releases/download/${CRI_VERSION}/crictl-${CRI_VERSION}-linux-amd64.tar.gz" | tar -C /opt/bin -xz

# Install the Kubernetes components
RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
mkdir -p /opt/bin
cd /opt/bin
curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
chmod +x {kubeadm,kubelet,kubectl}

# Create a few directories needed for operation
/bin/mkdir -p /var/lib/rook /var/lib/kubelet/volumeplugins /etc/kubernetes/manifests

# Enable volumeplugins in Kubelet for Rook
echo "KUBELET_EXTRA_ARGS=--volume-plugin-dir=/var/lib/kubelet/volumeplugins" > /etc/default/kubelet

# Download and install the systemd configs
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

# Enable systemd
systemctl enable kubelet.service

Install Kubernetes:

The following command finds the internal IP. The external ip will need to be populated in the kubeadm command.

priv_ip=$(ip -f inet -o addr show eth0|cut -d\  -f 7 | cut -d/ -f 1 | head -n 1)
/opt/bin/kubeadm init --apiserver-advertise-address=$priv_ip  --pod-network-cidr=192.168.0.0/16 --feature-gates Auditing=true --apiserver-cert-extra-sans <external ip>

Make note of the kubeadm join command at the end of the installation as it is used on the workers.

As non-root:

Copy the kubeconfig to core user:

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

Install networking

kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

Copy kubeconf to local machine

scp core@<external ip>:~/.kube/config ~/.kube/config-new

Alternatively if a kubeconfig already exists then the config can either be added to the yaml or be downloaded to another file (eg $HOME/.kube/config-new) and kubectl commands updated with --kubeconfig <newconf> (note: other tools like helm will need to be adjusted too)

Install Kubernetes Worker

On each worker node

sudo su -

systemctl enable docker && systemctl start docker

CNI_VERSION="v0.7.1"
mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz

CRI_VERSION="v1.11.1"
mkdir -p /opt/bin
curl -L "https://github.com/kubernetes-incubator/cri-tools/releases/download/${CRI_VERSION}/crictl-${CRI_VERSION}-linux-amd64.tar.gz" | tar -C /opt/bin -xz

RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
mkdir -p /opt/bin
cd /opt/bin
curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
chmod +x {kubeadm,kubelet,kubectl}

/bin/mkdir -p /var/lib/rook /var/lib/kubelet/volumeplugins /etc/kubernetes/manifests

echo "KUBELET_EXTRA_ARGS=--volume-plugin-dir=/var/lib/kubelet/volumeplugins" > /etc/default/kubelet

curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

systemctl enable kubelet.service

Join the worker to cluster

Example command

kubeadm join 10.0.0.2:6443 --token 123456 --discovery-token-ca-cert-hash sha256:123456
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment