Introduction and practice of pod in kubernetes

Source: Internet
Author: User
Tags k8s




Introduction and practice of pod in kubernetes

Kubernetes restart pod




what is kubernetes
The concept of pod

Restart pod kubernetes 
Detailed pod explanation can refer to k8s official website, the concept of pod mainly has the following points:
(1) Pod is the smallest and simplest unit that you can create and deploy in Kubernetes. A pod represents a process that runs in a cluster,kubernetes vs docker;
(2) How to use pod in kubrenetes cluster;
(3) How to manage multiple containers in pod

Kubernetes restart pod manually
Understanding Pod
It says "Pod is the smallest and simplest unit you can create and deploy in Kubernetes." A pod represents a process that runs in a cluster.kubernetes tutorial "Pods encapsulate the application's container (in some cases, several containers), the storage, the independent network IP, and the policy options that govern how the container runs." A pod represents a unit of deployment: an instance of an application in kubernetes that may be combined by one or more containers to share resources.
#说明Docker是kubernetes中最常用的容器运行时,但是Pod也支持其他容器运行时。
#容器进行时, see the following articles or blogs:
(1) Decryption container runtime
(2) Introduction to Kubernetes (k8s) container Runtime (CRI)
(3) Container runtime interface, container network interface,kubernetes certification container storage interface Analysis
Kubernetes why pod restart
One of two ways to use pods in a kubrenetes cluster
Run a container in a pod.
The pattern of "one container per Pod" is the most common use, in which you can think of pods as a single container encapsulation,kubernetes ingress  kuberentes managing pods rather than managing containers directly.
Restart pod kubernetes dashboard
#实战##创建一个nginx容器的可以定义为:cat pod1-deploymentapiVersion: v1kind: Podmetadata:name: nginx-testnamespace: testlabels:app: webspec:containers:- name: front-endimage: nginx:1.7.9ports:  - containerPort: 80
Kubernetes restart deployment pods

#创建podkubectl create -f pod1-deployment --namespace=testpod "nginx-test" created


#查看podkubectl get po --namespace=testNAME                          READY     STATUS    RESTARTS   AGEnginx-test                    1/1       Running   0          1m


#查看pod详细情况kubectl describe po nginx-test --namespace=testName:         nginx-testNamespace:    testNode:         swarm1/10.0.0.38Start Time:   Thu, 17 May 2018 17:33:50 +0800Labels:       app=webAnnotations:  <none>Status:       RunningIP:           10.244.2.131Containers:front-end:Container ID:   docker://5af319b84acfa076ac8500f39c81ff05e6664e6562d9593f5c7ba2fde0118372Image:          nginx:1.7.9Image ID:       docker-pullable://[email protected]:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451Port:           80/TCPHost Port:      0/TCPState:          Running  Started:      Thu, 17 May 2018 17:34:07 +0800Ready:          TrueRestart Count:  0Environment:    <none>Mounts:  /var/run/secrets/kubernetes.io/serviceaccount from default-token-z4ffx (ro)        ...        ...


#进入到pod(容器)内部kubectl exec -it nginx-test  /bin/bash --namespace=test[email protected]:/# nginx -vnginx version: nginx/1.7.9


##说明kubectl exec这条命令是对docker exec命令的包装,可以让你执行容器内部的命令,如果pod中只有一个容器在运行则此命令可以作用在pod上如:kubectl exec -it [pod] /bin/bash。我们可以使用如下命令来进入一个运行中的pod:kubectl exec -it [pod name] --/bin/bash,-i:用来启动标准输入流STDIN-t:将输入流定向到TTY(伪终端)中-c [container-name]:一个Pod中启动了多个容器,使用该参数来进入特定的容器中。

Two ways of using pod in kubrenetes cluster
Run multiple containers at the same time in one pod.
A pod can also encapsulate several containers that need to be tightly coupled to collaborate with each other, sharing resources among them. These containers in the same pod can collaborate with each other as a service unit-a container to share files, and another "sidecar" container to update these files. Pods manage the storage resources of these containers as an entity.

#实战##在一个pod里放置两个容器:nginx与rediscat test-deploymentapiVersion: v1kind: Podmetadata:name: rss-sitenamespace: testlabels:app: webspec:containers:- name: front-endimage: nginx:1.7.9ports:  - containerPort: 80- name: rss-readerimage: dockerhub.com/redis:3.2.8ports:  - containerPort: 88



# #说明: The document "image:dockerhub.com/redis:3.2.8" is not real, if necessary, please download it yourself!




#创建podkubectl create -f test-deployment --namespace=testpods "rss-site"created


#查看podkubectl get po --namespace=testNAME                          READY     STATUS    RESTARTS   AGErss-site                      2/2       Running   0          2h

#查看pod详细情况kubectl describe Po rss-site--namespace=testname:rss-sitenamespace:testnode:swarm1/10.0.           0.38Start Time:thu, 2018 16:31:57 +0800labels:app=webannotations: <none>status:runningip: 10.244.2.130containers:front-end:container id:docker://adb8115e7a559b0680a0a8bc79c4f535f1c6b8227acdb25f406c41b C7a29ac3cimage:nginx:1.7.9image id:docker-pullable://[email protected]:e3456c851a152494c3e4ff5fcc26f 240206abac0c9d794affb40e0714846c451port:80/tcphost port:0/tcpstate:running Started:thu, 2018 16:32:20 +0800ready:truerestart count:0environment: <none>mounts:/var/run/secrets/kuber Netes.io/serviceaccount from Default-token-z4ffx (RO) rss-reader:container id:docker:// 19e642c9bfa2fe2c5161ea015ea02c0470eb360744df452a28f975f81acce30aimage:dockerhub.datagrand.com/global/redis : 3.2.8Image id:docker-pullable://dockerhub.datagrand.com/global/[email protected]:d E7a70c04bb2de36bb32c44fe26ce92b9715922f80e07cb3f25aaf00a1f49bb5port:88/tcphost  Port:0/tcpstate:running Started:thu, May 2018 16:32:24 +0800ready:truerestart Count: 0Environment: <none>mounts:/var/run/secrets/kubernetes.io/serviceaccount from Default-token-z4ffx (RO)

#分别进入pod(容器)内部##进入front-endkubectl exec -it rss-site  -c front-end /bin/bash --namespace=test[email protected]:/# nginx -vnginx version: nginx/1.7.9


#进入rss-readekubectl exec -it rss-site  -c rss-reader  /bin/bash --namespace=test[email protected]:/data#



# #说明
Running multiple containers at the same time in one pod is a more advanced usage. Consider this pattern only when your container needs to work closely together. For example, you have a container that runs as a Web server, you need to use the shared volume, and there is another "sidecar" container to get resources from the remote to update these files, as shown in:



Pod Resources
Two kinds of resources can be shared in pods: network and storage.
(1) Network
Each pod will be assigned a unique IP address. All containers in the pod share network space, including IP addresses and ports. Containers inside the pod can communicate with each other using localhost. When a container in the pod communicates with the outside world, a shared network resource (such as a port mapping using a host) must be assigned.
(2) Storage
Multiple shared volume can be specified by pod. All containers in the pod have access to the shared volume. Volume can also be used to persist storage resources in the pod to prevent file loss after a container restart.
Using Pods
You rarely create a single pod directly in Kubernetes. Because the life cycle of the pod is short-lived, burn-in entities. When the pod is created (either directly or by another controller), it will be dispatched to the cluster node by kuberentes. The pod will remain on that node until the pod's process is terminated, deleted, evicted due to lack of resources, or node fails.
# #说明
(1) Restarting the pods in the pod is not the same as restarting the pod. The pod only provides the container's operating environment and keeps the container running, and restarting the container does not cause the pod to restart.
(2) pod does not heal. If the pod is running node failure, or if the scheduler itself fails, the pod will be deleted. Similarly, pods are evicted if the pod is in a node that lacks resources or if the pod is in a maintained state. Kubernetes uses a more advanced layer of abstraction called a controller to manage pod instances. Although you can use the pod directly, the controller is usually used to manage the pod in kubernetes.
Pods and controllers
Controllers can create and manage multiple pods, providing replica management, rolling upgrades, and cluster-level self-healing capabilities. For example, if a node fails, the controller can automatically dispatch pods on that node to other healthy nodes.
Specific examples can be consulted: creating and Managing multiple Pod--deployment


Introduction and practice of pod in kubernetes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.