- Learn OpenShift
- Denis Zuev Artemii Kropachev Aleksey Usov
- 352字
- 2021-08-13 16:03:52
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.
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.
推薦閱讀
- Linux操作系統(tǒng)基礎(chǔ)
- Linux實(shí)戰(zhàn)
- 鴻蒙生態(tài):開啟萬物互聯(lián)的智慧新時(shí)代
- Google系統(tǒng)架構(gòu)解密:構(gòu)建安全可靠的系統(tǒng)
- Arch Linux Environment Setup How-to
- 曝光:Linux企業(yè)運(yùn)維實(shí)戰(zhàn)
- SOA實(shí)踐者說
- 混沌工程:復(fù)雜系統(tǒng)韌性實(shí)現(xiàn)之道
- Linux操作系統(tǒng)應(yīng)用編程
- Python基礎(chǔ)教程(第3版)
- Windows 7中文版從入門到精通(修訂版)
- 嵌入式實(shí)時(shí)操作系統(tǒng)μC/OS原理與實(shí)踐
- 一學(xué)就會(huì):Windows Vista應(yīng)用完全自學(xué)手冊(cè)
- Kali Linux高級(jí)滲透測(cè)試
- 跟老男孩學(xué)Linux運(yùn)維:Shell編程實(shí)戰(zhàn)