官术网_书友最值得收藏!

Running Kubernetes pods

As with Docker, we can run a Kubernetes pod with the kubectl run command. Let's start with a simple web server example:

$ kubectl run httpd --image=httpd

We can verify the result by getting a list of Kubernetes pods, by running the kubectl get pods command:

$ kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-8576c89d7-qjd62 1/1 Running 0 6m
The first time you run this command, you will probably see that the Kubernetes pod status shows up as ContainerCreating. What is happening behind the scenes is that the Docker httpd image is being downloaded to Minikube VM. Be patient and give it some time to download the image. A few minutes later you should be able to see the container status is Running

The kubectl run command does more than just download an image and run a container out of it. We are going to cover this later in this chapter.

The 8576c89d7-qjd62 part is generated automatically. We are going to discuss this later in this chapter.

Essentially, this pod is a Docker container inside our Minikube VM, and we can easily verify this. First, we need to ssh into Minikube VM with minikube ssh, and then run the docker ps command:

$ minikube ssh
$
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c52c95f4d241 httpd "httpd -g 'daemon ..." 12 minutes ago Up 12 minutes k8s_httpd-container_httpd_default_39531635-23f8-11e8-ab32-080027dcd199_0
...
<output omitted>
...

We can try to kill this httpd Docker container, but Kubernetes will automatically spawn the new one:

$ docker rm -f c52c95f4d241   

Check the container status one more time:

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e5460e360b6 httpd "httpd -g 'daemon ..." 5 seconds ago Up 5 seconds k8s_httpd-container_httpd_default_4f5e05df-2416-11e8-ab32-080027dcd199_0
$ exit
Note that the httpd  container is still up, but with another ID. The initial ID was c52c95f4d241 and it became 5e5460e360b6 (you will have other IDs). That is one of the benefits of Kubernetes: if one container dies, Kubernetes will bring in a new one automatically. We are going to discuss this in detail later in this chapter.
主站蜘蛛池模板: 腾冲县| 道孚县| 曲沃县| 伊宁县| 和静县| 华阴市| 金溪县| 营山县| 大兴区| 巴南区| 金坛市| 南华县| 南充市| 五莲县| 许昌市| 鸡西市| 岳阳市| 阳城县| 兴海县| 柘城县| 余庆县| 海阳市| 酒泉市| 安国市| 容城县| 融水| 镇安县| 伊川县| 徐州市| 年辖:市辖区| 眉山市| 凯里市| 静海县| 沂源县| 夏津县| 宁武县| 军事| 元江| 双柏县| 甘南县| 敖汉旗|