Installing and Testing The Components of A Kubernetes Cluster
Installing and Testing The Components of A Kubernetes Cluster
a Kubernetes Cluster
Introduction
We have been given three nodes, in which we must install the components necessary to
build a running Kubernetes cluster. Once the cluster has been built and we have verified
all nodes are in the ready status, we need to start testing deployments, pods, services,
and port forwarding, as well as executing commands from a pod.
Solution
Log in to all three servers using the credentials on the lab page (either in your local
terminal, using the Instant Terminal feature, or using the public IPs), and work through
the objectives listed.
1. In all three terminals, run the following command to get the Docker gpg key:
1. In all three terminals, run the following command to get the Kubernetes gpg
key:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg |
sudo apt-key add -
1. In the Controller server terminal, run the following command to initialize the
cluster using kubeadm:
1. In the Controller server terminal, run the following commands to set up local
kubeconfig:
2. mkdir -p $HOME/.kube
3.
4. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
5.
sudo chown $(id -u):$(id -g) $HOME/.kube/config
1. In the Controller server terminal, run the following command to apply flannel:
kubectl apply -f
https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c86
81ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
Join the worker nodes to the cluster, and verify they have joined
successfully.
1. In the worker node terminals, run the following command to join the worker
nodes to the cluster (use the unique string in the kubeadm join included in the
output of kubeadm init in the Controller terminal):
sudo kubeadm join <your unique string from the output of kubeadm
init>
Run a deployment that includes at least one pod, and verify it was
successful.
1. In the Controller server terminal, run the following command to verify the pod is
up and running:
Use port forwarding to extend port 80 to 8081, and verify access to the
pod directly.
1. In the Controller server terminal, run the following command to forward the
container port 80 to 8081 (replace <pod_name> with the name in the output from
the previous command):
2. Open a new terminal session and log in to the Controller server. Then, run this
command to verify we can access this container directly:
1. In the original Controller server terminal, hit Ctrl+C to exit out of the running
program.
2. Still in Controller, execute the nginx version command from a pod (using the
same <pod_name> as before):
1. In the original Controller server terminal, run the following command to create a
NodePort service:
3. In one of the worker node terminals, verify its connectivity (get the $node_port
number from the PORT(S) column of the above service output):
curl -I localhost:$node_port
You have been given three nodes, in which you must install the components necessary
to build a running Kubernetes cluster. Once the cluster has been built and you have
verified all nodes are in the ready status, you need to start testing deployments, pods,
services, and port forwarding, as well as executing commands from a pod. You need to
perform the following in order to successfully complete this hands-on lab:
Get the Docker gpg key, add it to your repository, and install Docker.
Get the Kubernetes gpg key, add it to your repository, and install kubelet,
kubeadm, and kubectl.
Initialize the cluster.
Set up local kubeconfig.
Apply the flannel CNI as a network overlay.
Join the worker nodes to the cluster.
Verify the worker nodes have joined the cluster.
Run a deployment that includes at least one pod, and verify it was successful.
Verify the pod is running and available.
Use port forwarding to extend port 80 to 8081, and verify access to the pod.
Execute a command from the pod.
Create a service and verify connectivity via the node port.
Learning Objectives
check_circleGet the Docker gpg, and add it to your repository.keyboard_arrow_up
Run the following commands on all three nodes to get the Docker gpg key and add it to
your repository:
Run the following commands on all three nodes to get the Kubernetes gpg key and add
it to your repository:
Run the following command on all three nodes to install kubelet, kubeadm, and kubectl:
In the master node, run the following command to initialize the cluster using kubeadm:
In the master node, run the following commands to set up local kubeconfig:
mkdir -p $HOME/.kube
kubectl apply -f
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/
kube-flannel.yml
check_circleJoin the worker nodes to the cluster, and verify they have joined
successfully.keyboard_arrow_up
In both of the worker nodes, run the output of the kubeadm init command to join the
worker nodes to the cluster. Should look similar to:
In the master node, run the following commands to run a deployment of ngnix and
verify:
In the master node, run the following command to verify the pod is up and running:
Open a new shell to the Kubernetes master and run the following command:
NOTE: You must leave the previous session open in order to properly port forward. As
soon as you close that session, the port will NO LONGER be open.
In the original master node terminal, run this command to execute the nginx version
command from a pod:
In the original master node terminal, run the following commands to create a NodePort
service and view the service:
In one of the worker node terminals, run the following command to verify its
connectivity (get the $node_port number from the PORT(S) column of the above
service output):
curl -I localhost:$node_port