Pod - Declarative Way

After completing this session , you will be able to create Pod declaratively

So lets get started.

  • Lets create a YAML file for a nginx pod as webserver.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mypod
  labels:
     app: nginx
spec:
  containers:
  - name: nginx-demo
    image: nginx:1.9.1
    ports:
    - containerPort: 80
  • Create a Pod
$ kubectl create -f webserver.yaml
  • List the Pods
$ kubectl get pods
  • How to check the nginx webserver is running fine?
$ kubectl -n default port-forward mypod 8080:80
  • How to check the logs?
$ kubectl logs mypod
  • List the pods with more details
$ kubectl get pods -o wide
  • How to describe the pod
$ kubectl describe pod mypod
  • How to get a YAML output from a kubectl command?
$ kubectl get pod mypod -o yaml
  • How to delete a pod?
$ kubectl delete pod mypod