0% found this document useful (0 votes)
35 views

Installing and Testing The Components of A Kubernetes Cluster

Uploaded by

carlos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Installing and Testing The Components of A Kubernetes Cluster

Uploaded by

carlos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Installing and Testing the Components of

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.

Get the Docker gpg, and add it to your repository.

1. In all three terminals, run the following command to get the Docker gpg key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo


apt-key add -

2. Then add it to your repository:

sudo add-apt-repository "deb [arch=amd64]


https://download.docker.com/linux/ubuntu $(lsb_release -cs)
stable"

Get the Kubernetes gpg key, and add it to your repository.

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 -

2. Then add it to your repository:


3. cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
4. deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

5. Update the packages:

sudo apt-get update

Install Docker, kubelet, kubeadm, and kubectl.


1. In all three terminals, run the following command to install Docker, kubelet,
kubeadm, and kubectl:

sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu


kubelet=1.13.5-00 kubeadm=1.13.5-00 kubectl=1.13.5-00

Initialize the Kubernetes cluster.

1. In the Controller server terminal, run the following command to initialize the
cluster using kubeadm:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Set up local kubeconfig.

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

Apply the flannel CNI plugin as a network overlay.

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 run a


deployment of ngnix:

kubectl run nginx --image=nginx

2. Verify its success:

kubectl get deployments


Verify the pod is running and available.

1. In the Controller server terminal, run the following command to verify the pod is
up and running:

kubectl get pods

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):

kubectl port-forward <pod_name> 8081:80

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:

curl --head http://127.0.0.1:8081

We should see a status of OK.

Execute a command directly on a pod.

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):

kubectl exec -it <pod_name> -- nginx -v

Create a service, and verify connectivity on the node port.

1. In the original Controller server terminal, run the following command to create a
NodePort service:

kubectl expose deployment nginx --port 80 --type NodePort

2. View the service:

kubectl get services

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

We should see a status of OK.


Conclusion
Congratulations on completing this lab!

Additional Information and Resources

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:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key


add -

sudo add-apt-repository "deb [arch=amd64]


https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
check_circleGet the Kubernetes gpg key, and add it to your
repository.keyboard_arrow_up

Run the following commands on all three nodes to get the Kubernetes gpg key and add
it to your repository:

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo


apt-key add -

cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list


deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
check_circleInstall Docker, kubelet, kubeadm, and kubectl.keyboard_arrow_up

Run the following command on all three nodes to install kubelet, kubeadm, and kubectl:

sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu


kubelet=1.13.5-00 kubeadm=1.13.5-00 kubectl=1.13.5-00
check_circleInitialize the Kubernetes cluster.keyboard_arrow_up

In the master node, run the following command to initialize the cluster using kubeadm:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16


check_circleSet up local kubeconfig.keyboard_arrow_up

In the master node, run the following commands to set up local kubeconfig:

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config


check_circleApply the flannel CNI plugin as a network overlay.keyboard_arrow_up

In the master node, run the following command to apply flannel:

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:

sudo kubeadm join 'KUBERNETES_MASTER_IP':6443 --token 'UNIQUE_TOKEN'


--discovery-token-ca-cert-hash sha256:'UNIQUE_HASH'
check_circleRun a deployment that includes at least one pod, and verify it was
successful.keyboard_arrow_up

In the master node, run the following commands to run a deployment of ngnix and
verify:

kubectl create deployment nginx --image=nginx

kubectl get deployments


check_circleVerify the pod is running and available.keyboard_arrow_up

In the master node, run the following command to verify the pod is up and running:

kubectl get pods


check_circleUse port forwarding to extend port 80 to 8081, and verify access to the pod
directly.keyboard_arrow_up
In the master node, run the following command to forward the container port 80 to
8081:

kubectl port-forward [pod_name] 8081:80

Open a new shell to the Kubernetes master and run the following command:

curl --head http://127.0.0.1:8081

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.

check_circleExecute a command directly on a pod.keyboard_arrow_up

In the original master node terminal, run this command to execute the nginx version
command from a pod:

kubectl exec -it <pod_name> -- nginx -v


check_circleCreate a service, and verify connectivity on the node
port.keyboard_arrow_up

In the original master node terminal, run the following commands to create a NodePort
service and view the service:

kubectl expose deployment nginx --port 80 --type NodePort

kubectl get services

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

You might also like