[Kubernetes] Kubectl and Pod

1. Create and run a Pod

kubectl run my-nginx --image=nginx:alpine

We can run

kubectl get all

to see what has been created:

2. Delete a Pod:

kubectl delete pod my-nginx-65959bc4b9-dfvwh

Then run:

kubectl get pods

I found a new pod get created.

my-nginx-65959bc4b9-ltvxs

3. This is because the 'deployment' is trying to keep the current state, if I have one pod, and 'deploment' trying to keep one pod alive: which means if I deleted one, 'deployment' will create a new pod. After's why you see another pod pop up.

4. But this point, we have one pod, but we cannot access it. 

There is nothing in http://localhost:8080/

That's becaue we don't forward the port to external world. To do it:

kubectl port-forward my-nginx-65959bc4b9-ltvxs 8080:80

After that we can see the welcome page from nginx.

5. So actually how to delete a pod? Actually, if you want to delete a Pod,  you should delete the whole 'deployment;:

kubectl delete deployment my-nginx

6. We can check again:

kubectl get pods 
// No resources found.
原文地址:https://www.cnblogs.com/Answer1215/p/11749420.html