Deploy a Kubernetes Nginx Pod

KubernetesKubernetesBeginner
Practice Now

Introduction

In this challenge, you will be tasked with deploying a Kubernetes pod running the latest Nginx web server. Your goal is to ensure the pod is up and running and accessible through a service. You will need to create a Kubernetes YAML file to deploy the pod and a service of type NodePort to expose the Nginx pod.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL kubernetes(("Kubernetes")) -.-> kubernetes/BasicCommandsGroup(["Basic Commands"]) kubernetes(("Kubernetes")) -.-> kubernetes/AdvancedCommandsGroup(["Advanced Commands"]) kubernetes/BasicCommandsGroup -.-> kubernetes/create("Create") kubernetes/BasicCommandsGroup -.-> kubernetes/expose("Expose") kubernetes/AdvancedCommandsGroup -.-> kubernetes/apply("Apply") subgraph Lab Skills kubernetes/create -.-> lab-433745{{"Deploy a Kubernetes Nginx Pod"}} kubernetes/expose -.-> lab-433745{{"Deploy a Kubernetes Nginx Pod"}} kubernetes/apply -.-> lab-433745{{"Deploy a Kubernetes Nginx Pod"}} end

Deploy a Kubernetes Nginx Pod

As a new DevOps engineer, you've been tasked with deploying a Kubernetes pod running the latest Nginx web server. Your goal is to ensure the pod is up and running and accessible through a service.

Tasks

  • Create a Kubernetes YAML file to deploy a pod running the latest Nginx container.
  • Create a service of type NodePort to expose the Nginx pod.

Requirements

  • Create the Kubernetes YAML file in the ~/project directory.
  • Name the YAML file nginx-pod.yaml.
  • The Nginx container image version must be the latest.
  • The service must be of type NodePort.

Examples

Example YAML file content:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  type: placeholder
  ports:
    - port: 80
      targetPort: 80

Example service access URL:

http://<node-ip>:<node-port>

Hints

  • Use kubectl commands to interact with the Kubernetes cluster.
  • Ensure the pod is running and the service is exposing the pod correctly.
โœจ Check Solution and Practice

Summary

In summary, this challenge requires you to deploy a Kubernetes pod running the latest Nginx web server and create a service to expose the pod. You will need to create a Kubernetes YAML file to define the pod and service, ensuring the pod is up and running and accessible through the NodePort service.