> For the complete documentation index, see [llms.txt](https://jeffgthompsons-organization.gitbook.io/yellow-team/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jeffgthompsons-organization.gitbook.io/yellow-team/training/cloud-guru/learn-kubernetes-by-doing/creating-a-service-and-discovering-dns-names-in-kubernetes.md).

# Creating a Service and Discovering DNS Names in Kubernetes

## Create an nginx deployment, and verify it was successful

Use this command to create an nginx deployment:

```
kubectl run nginx --image=nginx
```

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FYZyo70NUm1DFGI3th04u%2Fimage.png?alt=media&amp;token=9235f871-31c7-4345-aea8-5caf199bf000" alt=""><figcaption></figcaption></figure>

Use this command to verify deployment was successful:

```
kubectl get deployments
```

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2F98Vx3FvzyMsWrPqf6sYJ%2Fimage.png?alt=media&amp;token=078a1720-c3ba-40a2-8ae9-5351ea53bf23" alt=""><figcaption></figcaption></figure>

## Create a service, and verify the service was successful

Use this command to create a service:

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

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FYO8488I3g2h8JWZ1pKKQ%2Fimage.png?alt=media&amp;token=01bf9364-bfce-4085-95b7-c1fda6a8ae32" alt=""><figcaption></figcaption></figure>

Use this command to verify the service was created:

```
kubectl get services
```

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FMuXEbZkWHXreiAb5Kads%2Fimage.png?alt=media&amp;token=0e091606-6ac4-4e3f-8b1b-bb07998e95b6" alt=""><figcaption></figcaption></figure>

## 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:**

**busybox.yaml**

```
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
```

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FpL7G4lFSxuA8gxgkclVd%2Fimage.png?alt=media&amp;token=ab31a583-207d-4698-9ebc-453260ebc639" alt=""><figcaption></figcaption></figure>

## 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
```

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2FB16hcO7cSfuLCSveRzPQ%2Fimage.png?alt=media&amp;token=7c536fbf-696f-4ddc-9d1b-6ceba2d25adb" alt=""><figcaption></figcaption></figure>

## Record the DNS name

Record the name:

<figure><img src="https://2666479439-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLYaaERPa1yy1Qa8E1NQ%2Fuploads%2Fv4AFEnRnQ6OnwoyonSoV%2Fimage.png?alt=media&amp;token=bf8c8cfe-8ad9-423a-bcd1-b1a3c72ba93b" alt=""><figcaption></figcaption></figure>
