Original article, welcome to reprint. Reprint please specify: reprint from IT people story, thank you! K8S minimum scheduling unit Pod (62)

The concept of POD is very important in K8S. Firstly, IT is briefly introduced that POD is the smallest scheduling unit of K8S. A POD can contain one or more containers, and a POD shares a namespace. Source: github.com/limingios/d…




Demonstrate the pod

  1. Download the source code

Github.com/limingios/d…




  1. Pod_nginx. Yml demonstration

K8s API inside the format

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80

Copy the code



  1. The POD node starts to run

Verify that K8S passes through the minikube single node without problem

kubectl version
# to create pod
kubectl create -f pod_nginx.yml
# Check pod status
kubectl get pods
# Check pod status IP status
kubectl get pods -o wide
Copy the code









Enter minikube to view docker PS, inside is actually docker

minikube start
docker ps
docker exec -it nginxId
exit
Copy the code



View the pod Nginx network

docker network ls
Nginx is 172.17.0.4
docker network inspect bridge
exit
kubectl get pods -o wide
Copy the code









If you want to enter the container, you also need to enter the virtual machine, then docker PS find the ID, and finally docker exec. It doesn’t have to be that complicated.

# Enter the nginx container
kubectl exec -it nginx sh
Learn all the commands to enter the container
kubectl exec -it -h
Copy the code






# nginx All details of this Pods
kubectl describe pods nginx
Copy the code



Let’s see if Nginx is up and running via IP.

Minikube SSH ping 172.17.0.4 curl 172.17.0.4Copy the code



What do you want most now? What I want most is to have access to nginx services on the machine, not inside. In the original learning docker can be conducted in the way of -P port mapping. Kubectl in K8S can also see commands.

kubectl port-forward nginx 8080:80
Copy the code



PS: If pod is used to create a container, k8S will manage it, obtain the IP address of nginx, and map the port in the container. Docker-swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm swarm There is also a small problem, now it is using port-forward, it has to be open all the time, if closed, directly can not access, how to solve this problem? I’ll tell you next time!