Create and Manage Kubernetes Pods Using Declarative Approach¶
Let's see how you can create and manage kubernetes Pods declaratively.
Here is the Docker Image used in this tutorial: reyanshkharga/nginx
Step 1: Create Pod Manifest¶
First, we need to write the pod manifest as follows:
Required fields:
apiVersion
- Which version of the Kubernetes API you're using to create this object.kind
- What kind of object you want to create.metadata
- Data that helps uniquely identify the object, including a name string, UID , and - optional namespace.spec
- What state you desire for the object.
Step 2: Create Pod¶
Let's use kubectl apply
to apply the manifest and create the pod:
Step 3: List Pods¶
List pods and verify that the pod we created is up and running:
Step 4: Verify Application¶
Verify that the application in the container inside the pod is running properly:
# Start shell session inside the container
kubectl exec -it my-pod -- curl localhost
# Access application
curl localhost
Also, let's use kubectl port-forward
to access the application locally:
Open any browser and visit localhost:5000
.
Step 5: Delete Pod¶
References: