- 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.
推薦閱讀
- Citrix XenApp Performance Essentials
- Linux實戰
- Puppet實戰
- 大學計算機應用基礎實踐教程(Windows 7+Office 2013)
- Instant Handlebars.js
- 開源安全運維平臺OSSIM疑難解析:入門篇
- Extending Bootstrap
- Linux網絡內核分析與開發
- Android物聯網開發細致入門與最佳實踐
- Learning Magento 2 Administration
- jQuery UI Cookbook
- Linux服務器配置與管理
- Kali Linux高級滲透測試
- UI設計手繪表現從入門到精通
- Azure Resource Manager Templates Quick Start Guide