Following the instructions for using kubeadm to setup a Kubernetes cluster.
gcloud compute ssh controller0
sudo bash
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 docker.io
apt-get install -y kubelet kubeadm kubectl kubernetes-cni
kubeadm init
After kubeadm
completes, it will print out a kubeadm
command line. Keep a
copy of that. You'll need to run that on your worker. It has the shared secret,
and the host IP of the master, that will allow a worker node to join the
cluster.
It will look something like this:
kubeadm join --token=ced5ef.c5e083173f9eb4a9 10.121.0.2
At this point your cluster should be responding to kubectl
commands, though
it will be a cluster of only one node, the master.
kubectl get nodes
NAME STATUS AGE
controller0 Ready,master 14m
kubectl apply -f https://git.io/weave-kube
Confirm this worked by looking to see that your dns pod is running:
kubectl get pods --all-namespaces | grep "kube-dns.*Running"
kube-system kube-dns-2924299975-r40tz 4/4 Running 0 10m
gcloud compute ssh worker0
sudo bash
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
# Install docker if you don't have it already.
apt-get install -y docker.io
apt-get install -y kubelet kubeadm kubectl kubernetes-cni
Back on the master, you should be able to see your new worker node in the cluster:
kubectl get nodes
NAME STATUS AGE
controller0 Ready,master 8m
worker0 Ready 11s
Check that you can run a pod.
kubectl run nginx --image=nginx:latest
Wait for a minute or two while it initializes, and you should see:
kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-1984600839-rjcr6 1/1 Running 0 17s