Call us
Designing

Kubernetes for Beginners: 10 Simple Steps to Deploy Your First Pod

Learn the simple 10-step guide to deploying your first Kubernetes pod. Dive into the basics of container orchestration and start your cloud journey with Cpluz's expert insights. Get started today.


5 min readCpluz

Kubernetes for Beginners: 10 Simple Steps to Deploy Your First Pod

Kubernetes for Beginners: 10 Simple Steps to Deploy Your First Pod

As the world moves rapidly towards containerization, Kubernetes has emerged as the most popular platform for automating the deployment, scaling, and management of containerized applications. If you're new to Kubernetes, navigating its complex architecture can be overwhelming. In this article, we'll break down the process of deploying your first pod in 10 simple steps, providing a solid foundation to begin your Kubernetes journey.

Step 1: Install Kubernetes

Before we dive into deploying our first pod, you need to install Kubernetes on your system. The most straightforward way to do this is by using Minikube, a single-node Kubernetes cluster that runs locally on your computer. Once installed, verify that Kubernetes is running correctly by using the following command:

kubectl version --client

Step 2: Create a Pod YAML File

Kubernetes uses YAML or JSON files to define the desired state of your resources. For this example, we'll create a pod YAML file. Open your preferred text editor and create a new file named pod.yaml with the following content:

apiVersion: v1
kind: Pod
metadata:
  name: my-first-pod
spec:
  containers:
  - name: my-first-container
    image: nginx:latest
    ports:
    - containerPort: 80

Step 3: Explain the Pod YAML File

Let's break down the YAML file:

  • apiVersion and kind define the version of the Kubernetes API and the type of resource being created.
  • metadata provides additional information about the pod, such as its name.
  • spec defines the desired state of the pod, including the containers it should run.
  • containers lists the containers that should run within the pod. In this case, we're using the official nginx image.
  • ports specifies the port that the container listens on.

Step 4: Deploy the Pod

Now that we have our pod YAML file, let's deploy it using the following command:

kubectl apply -f pod.yaml

This will create a pod named my-first-pod with a single container running the nginx:latest image.

Step 5: Verify the Pod

To verify that our pod has been successfully created, use the following command:

kubectl get pods

This should list the my-first-pod in a running state.

Step 6: Access the Pod

To access the pod, you can use the kubectl exec command to run a command inside the container. Here's how you can access the default nginx web server running inside our pod:

kubectl exec -it my-first-pod -- /bin/bash

This will open a shell inside the container, allowing you to interact with it.

Step 7: Expose the Pod

Now that we can access our pod, let's expose it to the outside world. We can do this by creating a service that forwards traffic to our pod. Create a new file named service.yaml with the following content:

apiVersion: v1
kind: Service
metadata:
  name: my-first-service
spec:
  selector:
    app: my-first-pod
  ports:
  - name: http
    port: 80
    targetPort: 80
  type: LoadBalancer

This service will forward traffic to the pod running the my-first-pod label.

Step 8: Apply the Service

Apply the service YAML file using the following command:

kubectl apply -f service.yaml

This will create a service named my-first-service that forwards traffic to our pod.

Step 9: Get the Service IP

To access our pod from outside the cluster, we need to get the IP address of our service. You can do this using the following command:

kubectl get svc

This will list the my-first-service and its IP address.

Step 10: Access the Service

Finally, let's access our pod from outside the cluster. Open a web browser and navigate to the IP address of our service. You should see the default nginx web server running inside our pod.

Frequently Asked Questions

Q: What is a pod in Kubernetes?

A: A pod is the basic execution unit in Kubernetes. It represents a logical host for one or more containers.

Q: How do I create a pod in Kubernetes?

A: You can create a pod in Kubernetes by defining a pod YAML file and applying it using the kubectl apply command.

Q: What is a service in Kubernetes?

A: A service in Kubernetes is an abstraction that defines a set of pods and a network endpoint that provides a stable network identity and load balancing for accessing the pods.

Q: How do I expose a pod in Kubernetes?

A: You can expose a pod in Kubernetes by creating a service that forwards traffic to the pod.

About the Author

Rajendaran is the Lead Digital Strategist at Cpluz, where he blends creative design with data-driven marketing strategies to help Indian businesses build powerful and profitable online presences. With a strong background in technology and a passion for innovation, Rajendaran helps businesses navigate the ever-evolving digital landscape. His expertise spans the entire spectrum of digital marketing, from search engine optimization to social media marketing. When not crafting compelling digital experiences, Rajendaran enjoys staying up-to-date on the latest trends and technologies in the world of IT.


Ready to Elevate Your Brand?

At Cpluz, we've been building meaningful connections between brands and consumers through innovative design and technology since 1993. Whether you need a compelling logo, a high-performance website, or a robust digital marketing strategy, our team is here to help you achieve your business goals.

Let's discuss how we can bring your vision to life. Contact the Cpluz team today for a consultation.

Email: info@cpluz.com
Visit our website: cpluz.com