Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 2 KB

01_your_first_pod.md

File metadata and controls

55 lines (37 loc) · 2 KB

01 - Running your first Pod

Once the cluster is ready, you can run any docker image by executing:

kubectl run <name> --image=<image-name>

For example, running an nginx image is as simple as this:

➜  ~ kubectl run nginx-pod --image=nginx
deployment.apps "nginx-pod" created

You can then verify it is running via the dashboard, or with kubectl:

➜  ~ kubectl get all
NAME                             READY     STATUS    RESTARTS   AGE
pod/nginx-pod-5f885d67ff-nbg2q   1/1       Running   0          10s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   23m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-pod   1         1         1            1           10s

NAME                                   DESIRED   CURRENT   READY     AGE
replicaset.apps/nginx-pod-5f885d67ff   1         1         1         10s

You can interact with your newly created Pod (and deployment/replicaset) via kubectl, some things you can try out:

  • Read logs from the container (stdout)
  • Execute commands inside the pod (e.g. you can run a bash shell via kubectl exec -it <pod> /bin/bash)
  • Scale up (or down) the number of replicas in the deployment
  • Deploy a few different public images
  • Experiment by editing the deployment on the fly (via the kubernetes dashboard)

Cleaning up

The deployment (and all pods related to it) can be deleted via:

➜  ~ kubectl delete deployment nginx-pod
deployment.extensions "nginx-pod" deleted

Important: deleting a deployment will completely remove your application from the cluster, while deleting a pod will cause the cluster to restart it, according to the number of replicas desired/available.

Next step

You know how to run images published via dockerhub on kubernetes, now it's time to build your own image and deploy it with a more declarative approach (i.e. use a Deployment).