305-998-7702 | 415-800-2922 info@rx-m.com

Practice Drill

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

Run the following command:

kubectl run --image nginx nginx-drill

Create a NodePort service that allows you to send a curl request to the nginx-drill pod at port 80 through your machine’s IP address.

Practice Drill: Answer

First, run the command to create the pod:

$ kubectl run --generator run-pod/v1 --image nginx nginx-drill

pod/nginx-drill created


Then, use kubectl expose with the --type NodePort flag to create a nodePort service imperatively. Make sure to expose the pod since that is the was created by the initial run command:

$ kubectl expose --type NodePort --port 80 pod nginx-drill

service/nginx-drill exposed


After exposing the pod, list the services. You will see the nginx-drill NodePort service maps port 80 to a port within the 30000 range:

$ kubectl get svc

NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes        ClusterIP                443/TCP        33d
nginx-drill       NodePort           80:32402/TCP   10s


Finally, try to send a curl request to the nginx pod using your machine IP address:

$ ip a s | head

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:b3:d9:13 brd ff:ff:ff:ff:ff:ff
    inet brd scope global ens33
       valid_lft forever preferred_lft forever

$ curl

<!DOCTYPE html>
<title>Welcome to nginx!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<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>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>


As another exercise, create a ClusterIP service called other-svc using kubectl create and use a label selector to associate it with the nginx-drill deployment created above.