This tutorial will walk you through deploying a simple pod in Kubernetes. A pod is the smallest deployable unit in Kubernetes, representing one or more containers that share the same network and storage.
Before you start, make sure you have the following tools installed:
- Minikube - for setting up a local Kubernetes cluster
- kubectl - Kubernetes command-line tool
- Git - to clone this repository
If you haven't already, start Minikube:
minikube start
This command will spin up a local Kubernetes cluster. It may take a few minutes, depending on your system.
Check the status of your Minikube cluster:
minikube status
You should see that the components are running correctly.
Clone this repository to get the tutorial files:
git clone https://github.com/zashraf/byte-sized-tutorials.git
cd byte-sized-tutorials/kubernetes/03-deploy-a-pod
To create the pod, apply the provided YAML file:
kubectl apply -f pod.yaml
The pod.yaml
file contains the following configuration:
apiVersion: v1
kind: Pod
metadata:
name: my-first-pod
labels:
app: nginx
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80
This configuration creates a pod named my-first-pod
that runs a container using the nginx image, with port 80 exposed.
Verify that the pod is running:
kubectl get pods
If the pod is running, you should see the status as Running
.
-
Expose the Pod as a Service:
kubectl expose pod my-first-pod --type=NodePort --port=80
-
Get the Minikube IP and NodePort:
- Find the Minikube IP:
minikube ip
- Get the NodePort:
kubectl get services
Use the Minikube IP and NodePort to access Nginx in the browser:
http://<Minikube-IP>:<NodePort>
- Find the Minikube IP:
If you need more information about the pod or encounter any issues, describe the pod:
kubectl describe pod my-first-pod
To delete the pod and service, run:
kubectl delete pod my-first-pod
kubectl delete service my-first-pod
Congratulations! You have successfully deployed your first pod in Kubernetes. This basic example forms the foundation for working with Kubernetes, as all higher-level components build upon pods.
Stay tuned for the next tutorial, where we’ll cover using Kubernetes deployments to manage replicas and automate updates.