I am currently learning more about Kubernetes and need to make sure I’m understanding it correctly, which means more blogs about Kubernetes in my wording for future reference.
MiniKube
I’m running Kubernetes locally on my MacBook via MiniKube. If you want to follow along please install MiniKube as per the notes at: https://kubernetes.io/docs/tasks/tools/install-minikube/
Once installed Minikube can be started with the command minikube start , and the minikube dashboard can be launched using the command minikube dashboard , with minikube running I will be using kubectl to give commands to my Kubernetes cluster.
Pods
A pod in Kubernetes is a collection of containers and volumes running in the same execution environment. So if you have multiple applications in containers that rely on each other, think pods. If applications are running in the same pod, they share environment variables and IP address. If applications are running in different pods then they don’t share environment variables and IP addresses.
Pods Commands
- kubectl get pods
Lists all the pods running.
- kubectl run PODNAME –generator=run-pod/v1 –image=CONTAINER_IMAGE_NAME
Creates a pod named PODNAME using the container image named CONTAINER_IMAGE_NAME
- kubectl delete pod PODNAME
Deletes the pod named PODNAME
- kubectl describe pod PODNAME
Gives a detailed description about the pod named PODNAME
- kubectl port-forward PODNAME HOST_PORT:CONTAINER_PORT
Forwards a port from the host into the container.
Pod Manifest
Rather than launching a pod via the command line with the various options/flags, the same details can be entered into a pod manifest. A pod manifest is written in YAML format and contains all the details needed to create the pod.
I am going to use the nginx container image to launch a pod running nginx.

—
apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - image: nginx:latest name: nginx ports: - containerPort: 80 name: http protocol: TCP
—

kubectl get pods will then show the pod and its status. The status may show as starting for a few minutes as the pod is starting up.

Further details about the pod can be viewed using the kubectl describe pods nginx command.


As the pod contains nginx we can it a quick test by forwarding a host port into the container, in this case:
kubectl port-forward nginx 8080:80

And opening localhost:8080 (or 127.0.0.1:8080) in a web browser then brings up the default nginx webpage:

If you prefer a web interface then status of the pod can also be viewed via the Kubernetes / Minikube dashboard:

3 thoughts on “Creating A Pod (Kubernetes)”
Comments are closed.