Creating a Service and Discovering DNS Names in Kubernetes

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will be presented with a three-node cluster. You will be creating a simple nginx deployment, in which you must create a service from that deployment. In order to accomplish this, you will use the kubectl command line to create the deployment. Then, you will expose the deployment to create the service. When you have verified the service is up and running, you will create a busybox pod to test the DNS resolution to that service.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create an nginx deployment, and verify it was successful.

Use this command to create an nginx deployment:

kubectl run nginx --image=nginx

Use this command to verify deployment was successful:

kubectl get deployments
Create a service, and verify the service was successful.

Use this command to create a service:

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

Use this command to verify the service was created:

kubectl get services
Create a pod that will allow you to query DNS, and verify it’s been created.

Use the following YAML to create the busybox pod spec:

apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  containers:
  - image: busybox:1.28.4
    command:
      - sleep
      - "3600"
    name: busybox
  restartPolicy: Always

Use the following command to create the busybox pod:

kubectl create -f busybox.yaml

Use the following command to verify the pod was created successfully:

kubectl get pods
Perform a DNS query to the service.

Use the following command to query the DNS name of the nginx service:

kubectl exec busybox -- nslookup nginx
Record the DNS name.

Record the name of:

<service-name&gt.default.svc.cluster.local

Additional Resources

You have been given a three-node cluster. Within that cluster, you must perform the following tasks in order to create a service and resolve the DNS names for that service. You will create the necessary Kubernetes resources in order to perform this DNS query. To adequately complete this hands-on lab, you must have a working deployment, a working service, and be able to record the DNS name of the service within your Kubernetes cluster. This means you will perform the following tasks:

  • Create an nginx deployment using the latest nginx image.
  • Verify the deployment has been created successfully.
  • Create a service from the nginx deployment created in the previous objective.
  • Verify the service has been created successfully.
  • Create a pod that will allow you to perform the DNS query.
  • Verify that the pod has been created successfully.
  • Perform the DNS query to the service created in an earlier objective.
  • Record the DNS name of the service.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!