Skip to content

Commit a6e3be3

Browse files
authored
Merge pull request #24746 from gaoguangze111/update-page-docker-cli-to-kubectl
Update links in page docker-cli-to-kubectl.md
2 parents 2f5e9d5 + dcf5fd4 commit a6e3be3

File tree

1 file changed

+73
-74
lines changed

1 file changed

+73
-74
lines changed

content/zh/docs/reference/kubectl/docker-cli-to-kubectl.md

Lines changed: 73 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ reviewers:
55
- brendandburns
66
- thockin
77
---
8-
<!--
8+
<!--
99
---
1010
title: kubectl for Docker Users
1111
content_type: concept
1212
reviewers:
1313
- brendandburns
1414
- thockin
15-
---
15+
---
1616
-->
1717

1818
<!-- overview -->
19-
<!--
20-
You can use the Kubernetes command line tool kubectl to interact with the API Server. Using kubectl is straightforward if you are familiar with the Docker command line tool. However, there are a few differences between the docker commands and the kubectl commands. The following sections show a docker sub-command and describe the equivalent kubectl command.
19+
<!--
20+
You can use the Kubernetes command line tool kubectl to interact with the API Server. Using kubectl is straightforward if you are familiar with the Docker command line tool. However, there are a few differences between the docker commands and the kubectl commands. The following sections show a docker sub-command and describe the equivalent kubectl command.
2121
-->
2222
您可以使用 Kubernetes 命令行工具 kubectl 与 API 服务器进行交互。如果您熟悉 Docker 命令行工具,则使用 kubectl 非常简单。但是,docker 命令和 kubectl 命令之间有一些区别。以下显示了 docker 子命令,并描述了等效的 kubectl 命令。
2323

@@ -48,11 +48,11 @@ CONTAINER ID IMAGE COMMAND CREATED
4848

4949
kubectl:
5050

51-
<!--
51+
<!--
5252
```shell
5353
# start the pod running nginx
5454
kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
55-
```
55+
```
5656
-->
5757
```shell
5858
# 启动运行 nginx 的 Pod
@@ -77,11 +77,11 @@ deployment.apps/nginx-app env updated
7777
`kubectl` 命令打印创建或突变资源的类型和名称,然后可以在后续命令中使用。部署后,您可以公开新服务。
7878
{{< /note >}}
7979

80-
<!--
80+
<!--
8181
```shell
8282
# expose a port through with a service
8383
kubectl expose deployment nginx-app --port=80 --name=nginx-http
84-
```
84+
```
8585
-->
8686
```shell
8787
# 通过服务公开端口
@@ -91,10 +91,10 @@ kubectl expose deployment nginx-app --port=80 --name=nginx-http
9191
service "nginx-http" exposed
9292
```
9393

94-
<!--
95-
By using kubectl, you can create a [Deployment](/docs/concepts/workloads/controllers/deployment/) to ensure that N pods are running nginx, where N is the number of replicas stated in the spec and defaults to 1. You can also create a [service](/docs/concepts/services-networking/service/) with a selector that matches the pod labels. For more information, see [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster).
94+
<!--
95+
By using kubectl, you can create a [Deployment](/docs/concepts/workloads/controllers/deployment/) to ensure that N pods are running nginx, where N is the number of replicas stated in the spec and defaults to 1. You can also create a [service](/docs/concepts/services-networking/service/) with a selector that matches the pod labels. For more information, see [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster).
9696
-->
97-
在 kubectl 命令中,我们创建了一个 [Deployment](/docs/concepts/workloads/controllers/deployment/),这将保证有 N 个运行 nginx 的 pod(N 代表 spec 中声明的 replica 数,默认为 1)。我们还创建了一个 [service](/docs/concepts/services-networking/service/),其选择器与容器标签匹配。查看[使用服务访问群集中的应用程序](/docs/tasks/access-application-cluster/service-access-application-cluster) 获取更多信息。
97+
在 kubectl 命令中,我们创建了一个 [Deployment](/zh/docs/concepts/workloads/controllers/deployment/),这将保证有 N 个运行 nginx 的 pod(N 代表 spec 中声明的 replica 数,默认为 1)。我们还创建了一个 [service](/zh/docs/concepts/services-networking/service/),其选择器与容器标签匹配。查看[使用服务访问群集中的应用程序](/zh/docs/tasks/access-application-cluster/service-access-application-cluster) 获取更多信息。
9898

9999
<!--
100100
By default images run in the background, similar to `docker run -d ...`. To run things in the foreground, use [`kubectl run`](/docs/reference/generated/kubectl/kubectl-commands/#run) to create pod:
@@ -105,27 +105,27 @@ By default images run in the background, similar to `docker run -d ...`. To run
105105
kubectl run [-i] [--tty] --attach <name> --image=<image>
106106
```
107107

108-
<!--
108+
<!--
109109
Unlike `docker run ...`, if you specify `--attach`, then you attach `stdin`, `stdout` and `stderr`. You cannot control which streams are attached (`docker -a ...`).
110-
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
110+
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
111111
-->
112112
`docker run ...` 不同的是,如果指定了 `--attach` ,我们将连接到 `stdin``stdout``stderr`,而不能控制具体连接到哪个输出流(`docker -a ...`)。要从容器中退出,可以输入 Ctrl + P,然后按 Ctrl + Q。
113113

114-
<!--
114+
<!--
115115
Because the kubectl run command starts a Deployment for the container, the Deployment restarts if you terminate the attached process by using Ctrl+C, unlike `docker run -it`.
116-
To destroy the Deployment and its pods you need to run `kubectl delete deployment <name>`.
116+
To destroy the Deployment and its pods you need to run `kubectl delete deployment <name>`.
117117
-->
118118
因为我们使用 Deployment 启动了容器,如果您终止连接到的进程(例如 `ctrl-c`),容器将会重启,这跟 `docker run -it` 不同。
119119
如果想销毁该 Deployment(和它的 pod),您需要运行 `kubectl delete deployment <name>`
120120

121121
## docker ps
122122

123-
<!--
124-
To list what is currently running, see [kubectl get](/docs/reference/generated/kubectl/kubectl-commands/#get).
123+
<!--
124+
To list what is currently running, see [kubectl get](/docs/reference/generated/kubectl/kubectl-commands/#get).
125125
-->
126126
如何列出哪些正在运行?查看 [kubectl get](/docs/reference/generated/kubectl/kubectl-commands/#get)
127127

128-
<!--
128+
<!--
129129
docker:
130130
-->
131131
使用 docker 命令:
@@ -139,8 +139,8 @@ CONTAINER ID IMAGE COMMAND CREATED
139139
55c103fa1296 nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp nginx-app
140140
```
141141

142-
<!--
143-
kubectl:
142+
<!--
143+
kubectl:
144144
-->
145145
使用 kubectl 命令:
146146

@@ -155,13 +155,13 @@ ubuntu 0/1 Completed 0 20s
155155

156156
## docker attach
157157

158-
<!--
159-
To attach a process that is already running in a container, see [kubectl attach](/docs/reference/generated/kubectl/kubectl-commands/#attach).
158+
<!--
159+
To attach a process that is already running in a container, see [kubectl attach](/docs/reference/generated/kubectl/kubectl-commands/#attach).
160160
-->
161161
如何连接到已经运行在容器中的进程?查看 [kubectl attach](/docs/reference/generated/kubectl/kubectl-commands/#attach)
162162

163-
<!--
164-
docker:
163+
<!--
164+
docker:
165165
-->
166166
使用 docker 命令:
167167

@@ -193,20 +193,20 @@ kubectl attach -it nginx-app-5jyvm
193193
...
194194
```
195195

196-
<!--
197-
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
196+
<!--
197+
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
198198
-->
199199
要从容器中分离,可以输入 Ctrl + P,然后按 Ctrl + Q。
200200

201201
## docker exec
202202

203-
<!--
204-
To execute a command in a container, see [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec).
203+
<!--
204+
To execute a command in a container, see [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec).
205205
-->
206206
如何在容器中执行命令?查看 [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec)
207207

208-
<!--
209-
docker:
208+
<!--
209+
docker:
210210
-->
211211
使用 docker 命令:
212212

@@ -224,8 +224,8 @@ docker exec 55c103fa1296 cat /etc/hostname
224224
55c103fa1296
225225
```
226226

227-
<!--
228-
kubectl:
227+
<!--
228+
kubectl:
229229
-->
230230
使用 kubectl 命令:
231231

@@ -244,13 +244,13 @@ kubectl exec nginx-app-5jyvm -- cat /etc/hostname
244244
nginx-app-5jyvm
245245
```
246246

247-
<!--
248-
To use interactive commands.
247+
<!--
248+
To use interactive commands.
249249
-->
250250
执行交互式命令怎么办?
251251

252-
<!--
253-
docker:
252+
<!--
253+
docker:
254254
-->
255255
使用 docker 命令:
256256

@@ -266,21 +266,21 @@ kubectl exec -ti nginx-app-5jyvm -- /bin/sh
266266
# exit
267267
```
268268

269-
<!--
270-
For more information, see [Get a Shell to a Running Container](/docs/tasks/debug-application-cluster/get-shell-running-container/).
269+
<!--
270+
For more information, see [Get a Shell to a Running Container](/docs/tasks/debug-application-cluster/get-shell-running-container/).
271271
-->
272-
更多信息请查看[获取运行中容器的 Shell 环境](/docs/tasks/kubectl/get-shell-running-container/)
272+
更多信息请查看[获取运行中容器的 Shell 环境](/zh/docs/tasks/debug-application-cluster/get-shell-running-container/)
273273

274274
## docker logs
275275

276-
<!--
277-
To follow stdout/stderr of a process that is running, see [kubectl logs](/docs/reference/generated/kubectl/kubectl-commands/#logs).
276+
<!--
277+
To follow stdout/stderr of a process that is running, see [kubectl logs](/docs/reference/generated/kubectl/kubectl-commands/#logs).
278278
-->
279279
如何查看运行中进程的 stdout/stderr?查看 [kubectl logs](/docs/reference/generated/kubectl/kubectl-commands/#logs)
280280

281281

282-
<!--
283-
docker:
282+
<!--
283+
docker:
284284
-->
285285
使用 docker 命令:
286286

@@ -292,8 +292,8 @@ docker logs -f a9e
292292
192.168.9.1 - - [14/Jul/2015:01:04:03 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"
293293
```
294294

295-
<!--
296-
kubectl:
295+
<!--
296+
kubectl:
297297
-->
298298
使用 kubectl 命令:
299299

@@ -305,8 +305,8 @@ kubectl logs -f nginx-app-zibvs
305305
10.240.63.110 - - [14/Jul/2015:01:09:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
306306
```
307307

308-
<!--
309-
There is a slight difference between pods and containers; by default pods do not terminate if their processes exit. Instead the pods restart the process. This is similar to the docker run option `--restart=always` with one major difference. In docker, the output for each invocation of the process is concatenated, but for Kubernetes, each invocation is separate. To see the output from a previous run in Kubernetes, do this:
308+
<!--
309+
There is a slight difference between pods and containers; by default pods do not terminate if their processes exit. Instead the pods restart the process. This is similar to the docker run option `--restart=always` with one major difference. In docker, the output for each invocation of the process is concatenated, but for Kubernetes, each invocation is separate. To see the output from a previous run in Kubernetes, do this:
310310
-->
311311
现在是时候提一下 pod 和容器之间的细微差别了;默认情况下如果 pod 中的进程退出 pod 也不会终止,相反它将会重启该进程。这类似于 docker run 时的 `--restart=always` 选项, 这是主要差别。在 docker 中,进程的每个调用的输出都是被连接起来的,但是对于 kubernetes,每个调用都是分开的。要查看以前在 kubernetes 中执行的输出,请执行以下操作:
312312

@@ -318,20 +318,20 @@ kubectl logs --previous nginx-app-zibvs
318318
10.240.63.110 - - [14/Jul/2015:01:09:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
319319
```
320320

321-
<!--
322-
For more information, see [Logging Architecture](/docs/concepts/cluster-administration/logging/).
321+
<!--
322+
For more information, see [Logging Architecture](/docs/concepts/cluster-administration/logging/).
323323
-->
324-
查看[日志架构](/docs/concepts/cluster-administration/logging/)获取更多信息。
324+
查看[日志架构](/zh/docs/concepts/cluster-administration/logging/)获取更多信息。
325325

326326
## docker stop and docker rm
327327

328-
<!--
329-
To stop and delete a running process, see [kubectl delete](/docs/reference/generated/kubectl/kubectl-commands/#delete).
328+
<!--
329+
To stop and delete a running process, see [kubectl delete](/docs/reference/generated/kubectl/kubectl-commands/#delete).
330330
-->
331331
如何停止和删除运行中的进程?查看 [kubectl delete](/docs/reference/generated/kubectl/kubectl-commands/#delete)
332332

333-
<!--
334-
docker:
333+
<!--
334+
docker:
335335
-->
336336
使用 docker 命令:
337337

@@ -357,8 +357,8 @@ docker rm a9ec34d98787
357357
a9ec34d98787
358358
```
359359

360-
<!--
361-
kubectl:
360+
<!--
361+
kubectl:
362362
-->
363363
使用 kubectl 命令:
364364

@@ -390,28 +390,28 @@ kubectl get po -l run=nginx-app
390390
```
391391

392392
{{< note >}}
393-
<!--
394-
When you use kubectl, you don't delete the pod directly.You have to first delete the Deployment that owns the pod. If you delete the pod directly, the Deployment recreates the pod.
393+
<!--
394+
When you use kubectl, you don't delete the pod directly.You have to first delete the Deployment that owns the pod. If you delete the pod directly, the Deployment recreates the pod.
395395
-->
396396
请注意,我们不直接删除 pod。使用 kubectl 命令,我们要删除拥有该 pod 的 Deployment。如果我们直接删除 pod,Deployment 将会重新创建该 pod。
397397
{{< /note >}}
398398

399399
## docker login
400400

401-
<!--
402-
There is no direct analog of `docker login` in kubectl. If you are interested in using Kubernetes with a private registry, see [Using a Private Registry](/docs/concepts/containers/images/#using-a-private-registry).
401+
<!--
402+
There is no direct analog of `docker login` in kubectl. If you are interested in using Kubernetes with a private registry, see [Using a Private Registry](/docs/concepts/containers/images/#using-a-private-registry).
403403
-->
404-
在 kubectl 中没有对 `docker login` 的直接模拟。如果您有兴趣在私有镜像仓库中使用 Kubernetes,请参阅[使用私有镜像仓库](/docs/concepts/containers/images/#using-a-private-registry)
404+
在 kubectl 中没有对 `docker login` 的直接模拟。如果您有兴趣在私有镜像仓库中使用 Kubernetes,请参阅[使用私有镜像仓库](/zh/docs/concepts/containers/images/#using-a-private-registry)
405405

406406
## docker version
407407

408-
<!--
409-
To get the version of client and server, see [kubectl version](/docs/reference/generated/kubectl/kubectl-commands/#version).
408+
<!--
409+
To get the version of client and server, see [kubectl version](/docs/reference/generated/kubectl/kubectl-commands/#version).
410410
-->
411411
如何查看客户端和服务端的版本?查看 [kubectl version](/docs/reference/generated/kubectl/kubectl-commands/#version)
412412

413-
<!--
414-
docker:
413+
<!--
414+
docker:
415415
-->
416416
使用 docker 命令:
417417

@@ -431,8 +431,8 @@ Git commit (server): 0baf609
431431
OS/Arch (server): linux/amd64
432432
```
433433

434-
<!--
435-
kubectl:
434+
<!--
435+
kubectl:
436436
-->
437437
使用 kubectl 命令:
438438

@@ -446,13 +446,13 @@ Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.9+a3d1dfa6f4
446446

447447
## docker info
448448

449-
<!--
450-
To get miscellaneous information about the environment and configuration, see [kubectl cluster-info](/docs/reference/generated/kubectl/kubectl-commands/#cluster-info).
449+
<!--
450+
To get miscellaneous information about the environment and configuration, see [kubectl cluster-info](/docs/reference/generated/kubectl/kubectl-commands/#cluster-info).
451451
-->
452452
如何获取有关环境和配置的各种信息?查看 [kubectl cluster-info](/docs/reference/generated/kubectl/kubectl-commands/#cluster-info)
453453

454-
<!--
455-
docker:
454+
<!--
455+
docker:
456456
-->
457457
使用 docker 命令:
458458

@@ -478,8 +478,8 @@ ID: ADUV:GCYR:B3VJ:HMPO:LNPQ:KD5S:YKFQ:76VN:IANZ:7TFV:ZBF4:BYJO
478478
WARNING: No swap limit support
479479
```
480480

481-
<!--
482-
kubectl:
481+
<!--
482+
kubectl:
483483
-->
484484
使用 kubectl 命令:
485485

@@ -494,4 +494,3 @@ Grafana is running at https://108.59.85.141/api/v1/namespaces/kube-system/servic
494494
Heapster is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/monitoring-heapster/proxy
495495
InfluxDB is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy
496496
```
497-

0 commit comments

Comments
 (0)