diff --git a/sources/tech/20190607 4 tools to help you drive Kubernetes.md b/sources/tech/20190607 4 tools to help you drive Kubernetes.md index 553e03380d..4166d42d80 100644 --- a/sources/tech/20190607 4 tools to help you drive Kubernetes.md +++ b/sources/tech/20190607 4 tools to help you drive Kubernetes.md @@ -7,54 +7,52 @@ [#]: via: (https://opensource.com/article/19/6/tools-drive-kubernetes) [#]: author: (Scott McCarty https://opensource.com/users/fatherlinux/users/fatherlinux/users/fatherlinux/users/fatherlinux) -4 tools to help you drive Kubernetes +帮助你驾驭 Kubernetes 的 4 个工具 ====== -Learning to drive Kubernetes is more important that knowing how to build -it, and these tools will get you on the road fast. + +学习如何驾驭 Kubernetes 比如何建造它更重要,这些工具可以帮助你更快上路。 + ![Tools in a workshop][1] -In the third article in this series, _[Kubernetes basics: Learn how to drive first][2]_ , I emphasized that you should learn to drive Kubernetes, not build it. I also explained that there is a minimum set of primitives that you have to learn to model an application in Kubernetes. I want to emphasize this point: the set of primitives that you _need_ to learn are the easiest set of primitives that you _can_ learn to achieve production-quality application deployments (i.e., high-availability [HA], multiple containers, multiple applications). Stated another way, learning the set of primitives built into Kubernetes is easier than learning clustering software, clustered file systems, load balancers, crazy Apache configs, crazy Nginx configs, routers, switches, firewalls, and storage backends—all the things you would need to model a simple HA application in a traditional IT environment (for virtual machines or bare metal). +在本系列的第三篇文章中,[Kubernetes 基础:首先学习如何使用][2],我强调你应该学会驾驭 Kubernetes,而不是建造它。我还解释说,在 Kubernetes 中,你必须学习一组最小的原语来建模应用程序。我想强调这一点:你需要学习的这组原语是最简单的原语集,你可以通过它们学习如何实现生产级的应用程序部署(即高可用性[HA]、多容器、多应用程序)。换句话说,学习 Kubernetes 内置的原语集比学习集群软件、集群文件系统、负载平衡器、让人发疯的 Apache 和 Nginx 的配置、路由器、交换机、防火墙和存储后端更容易 —— 这些是你在传统的 IT 环境(虚拟机或裸机)中建模简单的 HA 应用程序所需要的东西。 -In this fourth article, I'll share some tools that will help you learn to drive Kubernetes quickly. +在这第四篇文章中,我将分享一些有助于你学习快速驾驭 Kubernetes 的工具。 -### 1\. Katacoda +### 1、Katacoda -[Katacoda][3] is the easiest way to test-drive a Kubernetes cluster, hands-down. With one click and five seconds of time, you have a web-based terminal plumbed straight into a running Kubernetes cluster. It's magnificent for playing and learning. I even use it for demos and testing out new ideas. Katacoda provides a completely ephemeral environment that is recycled when you finish using it. +[Katacoda][3] 是试驾 Kubernetes 集群的最简单方法。只需单击一下,五秒钟后就可以将基于 Web 的终端直接连接到正在运行的 Kubernetes 集群中。这对于使用和学习来说非常棒。我甚至将它用于演示和测试新想法。Katacoda 提供了一个完整的临时环境,在你使用完毕后可以回收利用。 ![OpenShift Playground][4] -[OpenShift playground][5] +*[OpenShift Playground][5]* ![Kubernetes Playground][6] -[Kubernetes playground][7] +*[Kubernetes Playground][7]* -Katacoda provides ephemeral playgrounds and deeper lab environments. For example, the [Linux Container Internals Lab][3], which I have run for the last three or four years, is built in Katacoda. +Katacoda 提供了一个临时的环境和更深的实验室环境。例如,我最近三四年讲的 [Linux Container Internals Lab][3] 是在 Katacoda 中构建的。 -Katacoda maintains a bunch of [Kubernetes and cloud tutorials][8] on its main site and collaborates with Red Hat to support a [dedicated learning portal for OpenShift][9]. Explore them both—they are excellent learning resources. +Katacoda 在其主站点上维护了若干 [Kubernetes 和云教程][8]并与 Red Hat 合作以支持[OpenShift 的专用学习门户][9]。 探索一下它们 —— 它们是极好的学习资源。 -When you first learn to drive a dump truck, it's always best to watch how other people drive first. +当你第一次学习驾驶翻斗车时,最好先观察一下其他人的驾驶方式。 -### 2\. Podman generate kube +### 2、Podman generate kube -The **podman generate kube** command is a brilliant little subcommand that helps users naturally transition from a simple container engine running simple containers to a cluster use case running many containers (as I described in the [last article][2]). [Podman][10] does this by letting you start a few containers, then exporting the working Kube YAML, and firing them up in Kubernetes. Check this out (pssst, you can run it in this [Katacoda lab][3], which already has Podman and OpenShift). - -First, notice the syntax to run a container is strikingly similar to Docker: +`podman generate kube` 命令是一个很棒的子命令,可以帮助用户自然地从运行简单容器的简单容器引擎转换到运行许多容器的集群用例(正如我在[上篇文章][2]中所描述的那样)。[Podman][10] 通过让你启动几个容器,然后导出工作的 Kube YAML,然后在 Kubernetes 中启动它来实现这一点。看看这个(你可以在 [Katacoda lab][3] 中运行它,它已经有了 Podman 和 OpenShift)。 +首先,请注意运行容器的语法与 Docker 非常相似: ``` -`podman run -dtn two-pizza quay.io/fatherlinux/two-pizza` +podman run -dtn two-pizza quay.io/fatherlinux/two-pizza ``` -But this is something other container engines don't do: - +不过这个是其它容器引擎所没有的: ``` -`podman generate kube two-pizza` +podman generate kube two-pizza ``` -The output: - +输出: ``` # Generation of Kubernetes YAML is still under development! @@ -66,125 +64,123 @@ The output: apiVersion: v1 kind: Pod metadata: -creationTimestamp: "2019-06-07T08:08:12Z" -labels: -app: two-pizza -name: two-pizza + creationTimestamp: "2019-06-07T08:08:12Z" + labels: + app: two-pizza + name: two-pizza spec: -containers: -\- command: -\- /bin/sh -\- -c -\- bash -c 'while true; do /usr/bin/nc -l -p 3306 < /srv/hello.txt; done' -env: -\- name: PATH -value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -\- name: TERM -value: xterm -\- name: HOSTNAME -\- name: container -value: oci -image: quay.io/fatherlinux/two-pizza:latest -name: two-pizza -resources: {} -securityContext: -allowPrivilegeEscalation: true -capabilities: {} -privileged: false -readOnlyRootFilesystem: false -tty: true -workingDir: / + containers: + - command: + - /bin/sh + - -c + - bash -c 'while true; do /usr/bin/nc -l -p 3306 < /srv/hello.txt; done' + env: + - name: PATH + value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: TERM + value: xterm + - name: HOSTNAME + - name: container + value: oci + image: quay.io/fatherlinux/two-pizza:latest + name: two-pizza + resources: {} + securityContext: + allowPrivilegeEscalation: true + capabilities: {} + privileged: false + readOnlyRootFilesystem: false + tty: true + workingDir: / status: {} -\--- +--- apiVersion: v1 kind: Service metadata: -creationTimestamp: "2019-06-07T08:08:12Z" -labels: -app: two-pizza -name: two-pizza + creationTimestamp: "2019-06-07T08:08:12Z" + labels: + app: two-pizza + name: two-pizza spec: -selector: -app: two-pizza -type: NodePort + selector: + app: two-pizza + type: NodePort status: -loadBalancer: {} + loadBalancer: {} ``` -You now have some working Kubernetes YAML, which you can use as a starting point for mucking around and learning, tweaking, etc. The **-s** flag created a service for you. [Brent Baude][11] is even working on new features like [adding Volumes/Persistent Volume Claims][12]. For a deeper dive, check out Brent's amazing work in his blog post "[Podman can now ease the transition to Kubernetes and CRI-O][13]." +你现在有了一些可以的工作 Kubernetes YAML,你可以用它作为起点来学习、调整等等。`-s` 标志可以为你创造一项服务。[Brent Baude][11] 甚至致力于[添加卷/持久卷宣告][12]等新功能。如果想进一步深入,请在 Brent 的博客文章中查看他很棒的文章《[Podman 现在可以轻松过渡到 Kubernetes 和 CRI-O][13]》。 -### 3\. oc new-app - -The **oc new-app** command is extremely powerful. It's OpenShift-specific, so it's not available in default Kubernetes, but it's really useful when you're starting to learn Kubernetes. Let's start with a quick command to create a fairly sophisticated application: +### 3、oc new-app +`oc new-app` 命令非常强大。它是特定于 OpenShift 的,所以它在默认的 Kubernetes 中不可用,但是当你开始学习 Kubernetes 时它非常有用。让我们从快速命令开始创建一个相当复杂的应用程序: ``` oc new-project -n example -oc new-app -f +oc new-app -f https://raw.githubusercontent.com/openshift/origin/master/examples/quickstarts/cakephp-mysql.json ``` -With **oc new-app** , you can literally steal templates from the OpenShift developers and have a known, good starting point when developing primitives to describe your own applications. After you run the above command, your Kubernetes namespace (in OpenShift) will be populated by a bunch of new, defined resources. +使用 `oc new-app`,你可以从 OpenShift 开发人员那里偷取模板,并在开发原语来描述你自己的应用程序时拥有一个已知良好的起点。运行上述命令后,你的 Kubernetes 命名空间(在 OpenShift 中)将由一堆新的已定义资源填充。 ``` -`oc get all` +oc get all ``` -The output: - +输出: ``` -NAME READY STATUS RESTARTS AGE -pod/cakephp-mysql-example-1-build 0/1 Completed 0 4m -pod/cakephp-mysql-example-1-gz65l 1/1 Running 0 1m -pod/mysql-1-nkhqn 1/1 Running 0 4m +NAME READY STATUS RESTARTS AGE +pod/cakephp-mysql-example-1-build 0/1 Completed 0 4m +pod/cakephp-mysql-example-1-gz65l 1/1 Running 0 1m +pod/mysql-1-nkhqn 1/1 Running 0 4m -NAME DESIRED CURRENT READY AGE -replicationcontroller/cakephp-mysql-example-1 1 1 1 1m -replicationcontroller/mysql-1 1 1 1 4m +NAME DESIRED CURRENT READY AGE +replicationcontroller/cakephp-mysql-example-1 1 1 1 1m +replicationcontroller/mysql-1 1 1 1 4m -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/cakephp-mysql-example ClusterIP 172.30.234.135 8080/TCP 4m -service/mysql ClusterIP 172.30.13.195 3306/TCP 4m +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +service/cakephp-mysql-example ClusterIP 172.30.234.135 8080/TCP 4m +service/mysql ClusterIP 172.30.13.195 3306/TCP 4m -NAME REVISION DESIRED CURRENT TRIGGERED BY -deploymentconfig.apps.openshift.io/cakephp-mysql-example 1 1 1 config,image(cakephp-mysql-example:latest) -deploymentconfig.apps.openshift.io/mysql 1 1 1 config,image(mysql:5.7) +NAME REVISION DESIRED CURRENT TRIGGERED BY +deploymentconfig.apps.openshift.io/cakephp-mysql-example 1 1 1 config,image(cakephp-mysql-example:latest) +deploymentconfig.apps.openshift.io/mysql 1 1 1 config,image(mysql:5.7) -NAME TYPE FROM LATEST -buildconfig.build.openshift.io/cakephp-mysql-example Source Git 1 +NAME TYPE FROM LATEST +buildconfig.build.openshift.io/cakephp-mysql-example Source Git 1 -NAME TYPE FROM STATUS STARTED DURATION -build.build.openshift.io/cakephp-mysql-example-1 Source Git@47a951e Complete 4 minutes ago 2m27s +NAME TYPE FROM STATUS STARTED DURATION +build.build.openshift.io/cakephp-mysql-example-1 Source Git@47a951e Complete 4 minutes ago 2m27s -NAME DOCKER REPO TAGS UPDATED -imagestream.image.openshift.io/cakephp-mysql-example docker-registry.default.svc:5000/example/cakephp-mysql-example latest About aminute ago +NAME DOCKER REPO TAGS UPDATED +imagestream.image.openshift.io/cakephp-mysql-example docker-registry.default.svc:5000/example/cakephp-mysql-example latest About aminute ago -NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD -route.route.openshift.io/cakephp-mysql-example cakephp-mysql-example-example.2886795271-80-rhsummit1.environments.katacoda.com cakephp-mysql-example None +NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD +route.route.openshift.io/cakephp-mysql-example cakephp-mysql-example-example.2886795271-80-rhsummit1.environments.katacoda.com cakephp-mysql-example None ``` -The beauty of this is that you can delete Pods, watch the replication controllers recreate them, scale Pods up, and scale them down. You can play with the template and change it for other applications (which is what I did when I first started). +这样做的好处是你可以删除 Pod,观察复制控制器重新创建它们,缩放 Pod。你可以使用模板并将其更改为其他应用程序(这是我第一次启动时所做的)。 -### 4\. Visual Studio Code +### 4、Visual Studio Code -I saved one of my favorites for last. I use [vi][14] for most of my work, but I have never found a good syntax highlighter and code completion plugin for Kubernetes (if you have one, let me know). Instead, I have found that Microsoft's [VS Code][15] has a killer set of plugins that complete the creation of Kubernetes resources and provide boilerplate. +我把我最喜欢的放在最后。我的大部分工作都使用 [vi][14],但我从来没有为 Kubernetes 找到一个好的语法高亮器和代码补完插件(如果有的话,请告诉我)。相反,我发现微软的 [VS Code][15] 有一套杀手级的插件,可以完成 Kubernetes 资源的创建并提供样板。 ![VS Code plugins UI][16] -First, install Kubernetes and YAML plugins shown in the image above. +首先,安装上图中显示的 Kubernetes 和 YAML 插件。 ![Autocomplete in VS Code][17] -Then, you can create a new YAML file from scratch and get auto-completion of Kubernetes resources. The example above shows a Service. +然后,你可以从头开始创建新的 YAML 文件,并自动补完 Kubernetes 资源。上面的示例显示了一个服务。 ![VS Code autocomplete filling in boilerplate for an object][18] -When you use autocomplete and select the Service resource, it fills in some boilerplate for the object. This is magnificent when you are first learning to drive Kubernetes. You can build Pods, Services, Replication Controllers, Deployments, etc. This is a really nice feature when you are building these files from scratch or even modifying the files you create with **Podman generate kube**. +当你使用自动补完并选择服务资源时,它会填充该对象的一些模板。当你第一次学习使用 Kubernetes 时,这非常棒。你可以构建 Pod、服务、复制控制器、部署等。当你从头开始构建这些文件甚至修改您使用 `podman generate kube` 创建的文件时,这是一个非常好的功能。 -### Conclusion +### 总结 -These four tools (six if you count the two plugins) will help you learn to drive Kubernetes, instead of building or equipping it. In my final article in the series, I will talk about why Kubernetes is so exciting for running so many different workloads. +这四个工具(如果算上两个插件,则为六个)将帮助你学习驾驭 Kubernetes,而不是构造或装备它。在本系列的最后一篇文章中,我将讨论为什么 Kubernetes 如此适合运行这么多不同的工作负载。 -------------------------------------------------------------------------------- @@ -192,7 +188,7 @@ via: https://opensource.com/article/19/6/tools-drive-kubernetes 作者:[Scott McCarty][a] 选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) +译者:[wxy](https://github.com/wxy) 校对:[校对者ID](https://github.com/校对者ID) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 @@ -200,7 +196,7 @@ via: https://opensource.com/article/19/6/tools-drive-kubernetes [a]: https://opensource.com/users/fatherlinux/users/fatherlinux/users/fatherlinux/users/fatherlinux [b]: https://github.com/lujun9972 [1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/tools_workshop_blue_mechanic.jpg?itok=4YXkCU-J (Tools in a workshop) -[2]: https://opensource.com/article/19/6/kubernetes-basics +[2]: https://linux.cn/article-11036-1.html [3]: https://learn.openshift.com/subsystems/container-internals-lab-2-0-part-1 [4]: https://opensource.com/sites/default/files/uploads/openshift-playground.png (OpenShift Playground) [5]: https://learn.openshift.com/playgrounds/openshift311/