Creating a Kubernetes Pod
Defining a Pod in YAML
To create a Kubernetes Pod, you need to define a Pod specification in a YAML file. Here's an example:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx:latest
ports:
- containerPort: 80
This YAML file defines a Pod with a single container running the latest version of the Nginx web server, and exposes port 80 on the container.
Creating a Pod
You can create the Pod by running the following command in your terminal:
kubectl apply -f pod.yaml
This will create the Pod in your Kubernetes cluster.
Verifying the Pod
You can verify that the Pod has been created by running the following command:
kubectl get pods
This will list all the Pods in your Kubernetes cluster, including the one you just created.
Accessing the Pod
To access the container running inside the Pod, you can use the following command:
kubectl exec -it my-pod -- /bin/bash
This will open a shell inside the container, allowing you to interact with the running application.
Deleting a Pod
To delete the Pod, you can run the following command:
kubectl delete pod my-pod
This will delete the Pod and its associated resources from your Kubernetes cluster.