Adventures in Freebernetes Tutorial: Build Your Own Bare-VM k3s Cluster

Part 6: Test the Cluster

We’ll run the following tests:

  1. Create nginx deployment
  2. Port-forward to nginx pod
  3. Check nginx pod’s logs
  4. Expose nginx NodePort Service
  5. Expose nginx LoadBalancer Service on port 8080
  6. Test pod-to-pod connectivity
~ # kubectl create deployment nginx –image=nginx
deployment.apps/nginx created
~ # kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-wt9qr 1/1 Running 0 53m
~ # POD=$(kubectl get pods -l app=nginx -ojsonpath="{.items[0].metadata.name}")
~ # PID="$(kubectl port-forward $POD 8080:80 >/dev/null 2>&1 & echo $!)"
~ # curl http://localhost:8080/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a&gt;.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a&gt;.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
~ # kill "$PID"
~ # kubectl logs $POD
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
127.0.0.1 – – [26/Dec/2020:05:36:22 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.73.0" "-"
~ # kubectl expose deployment nginx –port 80 –type NodePort
service/nginx exposed
~ # kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.2.0.1 <none> 443/TCP 4h14m
nginx NodePort 10.2.37.161 <none> 80:30234/TCP 11s
~ # CLUSTERIP="$(kubectl get svc nginx -ojsonpath='{.spec.clusterIP}')"
~ # curl -I http://${CLUSTERIP}/
HTTP/1.1 200 OK
Server: nginx/1.19.6
Date: Sat, 26 Dec 2020 07:20:34 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 15 Dec 2020 13:59:38 GMT
Connection: keep-alive
ETag: "5fd8c14a-264"
Accept-Ranges: bytes
~ # kubectl delete svc nginx
service "nginx" deleted
~ # kubectl expose deployment nginx –port 8080 –target-port 80 –type LoadBalancer
service/nginx exposed
~ # kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.2.0.1 <none> 443/TCP 6h26m
nginx LoadBalancer 10.2.196.18 10.0.10.21 8080:32282/TCP 11s
~ # LBIP="$(kubectl get svc nginx -ojsonpath='{.status.loadBalancer.ingress[0].ip}')"
~ # curl -I http://${LBIP}:8080/
HTTP/1.1 200 OK
Server: nginx/1.19.6
Date: Sat, 26 Dec 2020 07:51:23 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 15 Dec 2020 13:59:38 GMT
Connection: keep-alive
ETag: "5fd8c14a-264"
Accept-Ranges: bytes
~ # PODIP="$(kubectl get pod "$POD" -ojsonpath='{.status.podIP}')"
~ # kubectl run -it busybox –image busybox –rm=true –restart=Never — wget -q -S -O /dev/null http://${PODIP}/
HTTP/1.1 200 OK
Server: nginx/1.19.6
Date: Sat, 26 Dec 2020 08:20:54 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 15 Dec 2020 13:59:38 GMT
Connection: close
ETag: "5fd8c14a-264"
Accept-Ranges: bytes
pod "busybox" deleted
~ #
# Create deployment
kubectl create deployment nginx –image=nginx
kubectl get pods
# Port-forward to pod
POD=$(kubectl get pods -l app=nginx -ojsonpath="{.items[0].metadata.name}")
PID="$(kubectl port-forward $POD 8080:80 >/dev/null 2>&1 & echo $!)"
curl http://localhost:8080/
kill "$PID"
# Check pod logs
kubectl logs $POD
# Create NodePort service
kubectl expose deployment nginx –port 80 –type NodePort
kubectl get svc
CLUSTERIP="$(kubectl get svc nginx -ojsonpath='{.spec.clusterIP}')"
curl -I http://${CLUSTERIP}/
kubectl delete svc nginx
# Create LoadBalancer Service
kubectl expose deployment nginx –port 8080 –target-port 80 –type LoadBalancer
kubectl get svc
LBIP="$(kubectl get svc nginx -ojsonpath='{.status.loadBalancer.ingress[0].ip}')"
curl -I http://${LBIP}:8080/
kubectl delete svc nginx
# Test pod-to-pod connectivity
PODIP="$(kubectl get pod "$POD" -ojsonpath='{.status.podIP}')"
kubectl run -it busybox –image busybox –rm=true –restart=Never — wget -q -S -O /dev/null http://${PODIP}/
view raw commands.sh hosted with ❤ by GitHub

Pages: 1 2 3 4 5 6 7 8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: