K8s Create Pod - varoonsahgal/cg-cloud-foundations GitHub Wiki

Minikube startup

Run these 2 commands:

minikube delete
minikube start

Kubernetes Create a Pod

The following is an example of a Pod which consists of a container running the image nginx:1.17.0

  • Open your terminal and create a directory using the syntax mkdir k8s
  • Get inside the directory using the syntax cd k8s
  • Create a configuration file using the syntax touch sample-pod.yaml
  • Open the file using an text editor - For example use vi sample-pod.yaml
  • Add the following set of instructions
apiVersion: v1
kind: Pod
metadata:
  name: my-nginx-pod
  labels:
    app: nginx
spec:
  containers:
  - name: nginx-container
    image: nginx:1.17.0
  • Run the command kubectl apply -f sample-pod.yaml
  • To check the pod creation - use syntax kubectl get all or kubectl get pods
  • To get more details about the pod using the name - use syntax kubectl describe pod/my-nginx-pod
  • To launch the shell inside our pod use syntax - kubectl exec -it my-nginx-pod -- /bin/bash
  • Once inside the pod, try running curl http://localhost
  • But, it will complain that curl is not found.
  • Think: If we wanted to install curl, would this be the right place to do that??