[zh] updated docker-cli-to-kubectl.md

pull/37570/head
windsonsea 2022-10-28 09:31:39 +08:00
parent 1db4807ef9
commit b013a56257
1 changed files with 20 additions and 19 deletions

View File

@ -18,7 +18,6 @@ You can use the Kubernetes command line tool `kubectl` to interact with the API
则使用 kubectl 非常简单。但是Docker 命令和 kubectl 命令之间有一些区别。以下显示了 Docker 子命令,
并描述了等效的 `kubectl` 命令。
<!-- body -->
## docker run
@ -30,7 +29,7 @@ To run an nginx Deployment and expose the Deployment, see [kubectl create deploy
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker run -d --restart=always -e DOMAIN=cluster --name nginx-app -p 80:80 nginx
@ -67,7 +66,7 @@ deployment.apps/nginx-app created
```
```shell
# add env to nginx-app
# 添加 env 到 nginx-app
kubectl set env deployment/nginx-app DOMAIN=cluster
```
```
@ -99,9 +98,9 @@ service "nginx-http" exposed
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).
-->
在 kubectl 命令中,我们创建了一个 [Deployment](/zh-cn/docs/concepts/workloads/controllers/deployment/)
这将保证有 N 个运行 nginx 的 PodN 代表 spec 中声明的 replica 数,默认为 1
我们还创建了一个 [service](/zh-cn/docs/concepts/services-networking/service/),其选择与容器标签匹配。
查看[使用服务访问集群中的应用程序](/zh-cn/docs/tasks/access-application-cluster/service-access-application-cluster) 获取更多信息。
这将保证有 N 个运行 nginx 的 PodN 代表 spec 中声明的副本数,默认为 1
我们还创建了一个 [service](/zh-cn/docs/concepts/services-networking/service/),其选择算符与容器标签匹配。
查看[使用服务访问集群中的应用程序](/zh-cn/docs/tasks/access-application-cluster/service-access-application-cluster)获取更多信息。
<!--
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:
@ -117,7 +116,7 @@ kubectl run [-i] [--tty] --attach <name> --image=<image>
Unlike `docker run ...`, if you specify `--attach`, then you attach `stdin`, `stdout` and `stderr`. You cannot control which streams are attached (`docker -a ...`).
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
-->
`docker run ...` 不同的是,如果指定了 `--attach`,我们将连接到 `stdin``stdout` 和 `stderr`
`docker run ...` 不同的是,如果指定了 `--attach`,我们将连接到 `stdin``stdout` 和 `stderr`
而不能控制具体连接到哪个输出流(`docker -a ...`)。要从容器中退出,可以输入 Ctrl + P然后按 Ctrl + Q。
<!--
@ -137,8 +136,8 @@ To list what is currently running, see [kubectl get](/docs/reference/generated/k
<!--
docker:
-->
使用 docker 命令:
-->
使用 Docker 命令:
```shell
docker ps -a
@ -174,7 +173,7 @@ To attach a process that is already running in a container, see [kubectl attach]
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker ps
@ -219,7 +218,7 @@ To execute a command in a container, see [kubectl exec](/docs/reference/generate
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker ps
@ -263,7 +262,7 @@ To use interactive commands.
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker exec -ti 55c103fa1296 /bin/sh
@ -289,11 +288,10 @@ To follow stdout/stderr of a process that is running, see [kubectl logs](/docs/r
-->
如何查看运行中进程的 stdout/stderr查看 [kubectl logs](/docs/reference/generated/kubectl/kubectl-commands/#logs)。
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker logs -f a9e
@ -321,7 +319,7 @@ There is a slight difference between pods and containers; by default pods do not
-->
现在是时候提一下 Pod 和容器之间的细微差别了;默认情况下如果 Pod 中的进程退出 Pod 也不会终止,
相反它将会重启该进程。这类似于 docker run 时的 `--restart=always` 选项,这是主要差别。
docker 中,进程的每个调用的输出都是被连接起来的,但是对于 Kubernetes每个调用都是分开的。
Docker 中,进程的每个调用的输出都是被连接起来的,但是对于 Kubernetes每个调用都是分开的。
要查看以前在 Kubernetes 中执行的输出,请执行以下操作:
```shell
@ -337,7 +335,10 @@ For more information, see [Logging Architecture](/docs/concepts/cluster-administ
-->
查看[日志架构](/zh-cn/docs/concepts/cluster-administration/logging/)获取更多信息。
<!--
## docker stop and docker rm
-->
## docker stop 和 docker rm {#docker-stop-and-docker-rm}
<!--
To stop and delete a running process, see [kubectl delete](/docs/reference/generated/kubectl/kubectl-commands/#delete).
@ -347,7 +348,7 @@ To stop and delete a running process, see [kubectl delete](/docs/reference/gener
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker ps
@ -400,7 +401,7 @@ deployment "nginx-app" deleted
```shell
kubectl get po -l app=nginx-app
# Return nothing
# 什么都没有返回
```
{{< note >}}
@ -429,7 +430,7 @@ To get the version of client and server, see [kubectl version](/docs/reference/g
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker version
@ -470,7 +471,7 @@ To get miscellaneous information about the environment and configuration, see [k
<!--
docker:
-->
使用 docker 命令:
使用 Docker 命令:
```shell
docker info