Here we will test the cluster by creating a workload with a node port service and get the results using curl
Do the following on controlplane
Deploy and expose an nginx pod
kubectl create deployment nginx --image nginx:alpine
kubectl expose deploy nginx --type=NodePort --port 80
PORT_NUMBER=$(kubectl get service -l app=nginx -o jsonpath="{.items[0].spec.ports[0].nodePort}")
echo -e "\n\nService exposed on NodePort $PORT_NUMBER"
Hit the new service
curl http://node01:$PORT_NUMBER
curl http://node02:$PORT_NUMBER
If you get this error:
curl: (7) Failed to connect to node01 port 30659 after 0 ms: Connection refused
Wait a few seconds and try again. Both should return the nginx welcome message as HTML text.
Congratulations! You now have a working kubeadm cluster.
If you installed the cluster with bridge networking (the default), then you can view NodePort services with your browser.
Run the following command on controlplane
to get browser address, then copy the output to your browser:
echo "http://$(dig +short node01):$PORT_NUMBER"
node01
or node02
. If you did not note these down, you can find the IP addresses from the EC2 console by looking in the Public IPv4 ...
column (scroll right if this column is not in view).Form a URL using the IP address (it will be different for you) and the NodePort number output from step 1 above, e.g.
http://54.167.161.210:32182
You may also copy the KUBECONFIG to student-node
thus allowing you to run kubectl
commands from there:
student-node
.Run the following:
mkdir ~/.kube
scp controlplane:~/.kube/config ~/.kube/config
kubectl get pods -n kube-system
Prev: Worker nodes