From 75e5a753761c189ce10c79c6e048e861d2cd9edc Mon Sep 17 00:00:00 2001 From: geekpi Date: Wed, 4 Aug 2021 08:48:09 +0800 Subject: [PATCH] translated --- ... ways to manage Kubernetes with kubectl.md | 95 ------------------- ... ways to manage Kubernetes with kubectl.md | 95 +++++++++++++++++++ 2 files changed, 95 insertions(+), 95 deletions(-) delete mode 100644 sources/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md create mode 100644 translated/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md diff --git a/sources/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md b/sources/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md deleted file mode 100644 index 43855ac30a..0000000000 --- a/sources/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md +++ /dev/null @@ -1,95 +0,0 @@ -[#]: subject: (5 useful ways to manage Kubernetes with kubectl) -[#]: via: (https://opensource.com/article/21/7/kubectl) -[#]: author: (Alan Smithee https://opensource.com/users/alansmithee) -[#]: collector: (lujun9972) -[#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) - -5 useful ways to manage Kubernetes with kubectl -====== -Learn kubectl to enhance how you interact with Kubernetes. -![Ship captain sailing the Kubernetes seas][1] - -Kubernetes is software to help you run lots of containers in an organized way. Aside from providing tools to manage (or [orchestrate][2]) the containers you run, Kubernetes also helps those containers scale out as needed. With Kubernetes as your central control panel (or _control plane_), you need a way to manage Kubernetes, and the tool for that job is kubectl. The `kubectl` command lets you control, maintain, analyze, and troubleshoot Kubernetes clusters. As with many tools using the `ctl` (short for "control") suffix, such as systemctl and sysctl, kubectl has purview over a broad array of functions and tasks, so you end up using it a lot if you're running Kubernetes. It's a big command with lots of options, so here are five common tasks that kubectl makes easy. - -### 1\. List and describe resources - -Containers, by design, tend to multiply. Under certain conditions, they can multiply rapidly. This can get overwhelming if the only way you have to see running containers is `podman ps` or `docker ps`. With `kubectl get` and `kubectl describe`, you can get information about what pods are running and the containers they're handling. What's more is that you can get just the information you need by using options like `--namespace` or `name` or `--selector`. - -The `get` subcommand is useful for a lot more than just pods and containers. It has information about nodes, namespaces, deployments, services, and replicas. - -### 2\. Create resources - -If you've only ever created deployments through a web user interface (UI) like one provided by OpenShift, OKD, or Kubernetes, but you're looking to take control of your cluster from your Linux terminal instead, then get ready to use `kubectl create`. The `kubectl create` command doesn't just instantiate a new app deployment, though. There are lots of other components available in Kubernetes that you can create, such as services, quotas, and [CronJobs][3]. - -A CronJob in Kubernetes can create a transient pod meant to perform some task on a schedule of your choice. They're not difficult to set up. Here's a CronJob to have a BusyBox image echo "hello world" every minute: - - -``` -$ kubectl create cronjob \ -hello-world \ -\--image=busybox \ -\--schedule="*/1 * * * *" -- echo "hello world" -``` - -### 3\. Edit files - -You may have an understanding that objects in Kubernetes have accompanying configuration files, but rummaging through your filesystem to find the appropriate file can be troublesome. With `kubectl edit`, you can keep your mind on the objects and not on the files that define them. You can have `kubectl` find and open the file for you (it respects the `KUBE_EDITOR` environment variable, so you can set your editor to whatever you prefer): - - -``` -$ KUBE_EDITOR=emacs \ -kubectl edit cronjob/hello-world -``` - -### 4\. Trade files between containers - -Newcomers to containers are often baffled by the concept of a shared system that they can't apparently access. They may learn about `exec` options in their container engine or in kubectl itself, but containers still can seem impervious when they can't just grab a file from or place a file into a container. Using the `kubectl cp` command, you can treat containers as if they were remote servers, making copying files to and from containers no more complex than an SSH command: - - -``` -`$ kubectl cp foo my-pod:/tmp` -``` - -### 5\. Apply changes - -Making changes to Kubernetes objects can be done at any time with the `kubectl apply` command. All you have to do is point the command to a configuration file: - - -``` -`$ kubectl apply -f ./mypod.json` -``` - -Akin to running an Ansible playbook or a Bash script, `apply` makes it easy to "import" settings quickly into a running Kubernetes instance. For instance, the GitOps tool [ArgoCD][4] is surprisingly simple to install thanks to the `apply` subcommand: - - -``` -$ kubectl create namespace argocd -$ kubectl apply -n argocd \ --f -``` - -### Use kubectl - -Kubectl is a powerful tool, and because it's a terminal command it can be scripted and used in many ways a web UI cannot. Learning kubectl is a great way to further your understanding of Kubernetes, containers, pods, and all the technologies that surround these important cloud innovations. [Download our kubectl cheat sheet][5] for a quick reference, complete with sample commands, to help you as you learn and remind you of the details once you're a pro. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/21/7/kubectl - -作者:[Alan Smithee][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/alansmithee -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/ship_captain_devops_kubernetes_steer.png?itok=LAHfIpek (Ship captain sailing the Kubernetes seas) -[2]: https://opensource.com/article/20/11/orchestration-vs-automation -[3]: https://opensource.com/article/20/11/kubernetes-jobs-cronjobs -[4]: https://argoproj.github.io/argo-cd/ -[5]: https://opensource.com/downloads/kubectl-cheat-sheet diff --git a/translated/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md b/translated/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md new file mode 100644 index 0000000000..efa41cd495 --- /dev/null +++ b/translated/tech/20210723 5 useful ways to manage Kubernetes with kubectl.md @@ -0,0 +1,95 @@ +[#]: subject: (5 useful ways to manage Kubernetes with kubectl) +[#]: via: (https://opensource.com/article/21/7/kubectl) +[#]: author: (Alan Smithee https://opensource.com/users/alansmithee) +[#]: collector: (lujun9972) +[#]: translator: (geekpi) +[#]: reviewer: ( ) +[#]: publisher: ( ) +[#]: url: ( ) + +用 kubectl 管理 Kubernetes 的 5 种有用方法 +====== +学习kubectl,提升你与 Kubernetes 的互动方式。 +![Ship captain sailing the Kubernetes seas][1] + +Kubernetes 是帮助你以有组织的方式运行大量容器的软件。除了提供工具来管理(或[编排][2])运行的容器,Kubernetes 还帮助这些容器根据需要进行扩展。有了 Kubernetes 作为你的中央控制面板(或称 _control plane_),你需要一种方法来管理 Kubernetes,而这项工作的工具就是 kubectl。`kubectl` 命令让你控制、维护、分析和排除 Kubernetes 集群的故障。与许多使用 `ctl`(“控制”的缩写)后缀的工具一样,如 systemctl 和 sysctl,kubectl 拥有大量的功能和任务权限,所以如果你正在运行 Kubernetes,你最终会经常使用它。它是一个有很多选项的大命令,所以下面是 kubectl 使之变得简单的五个常见任务。 + +### 1\. 列出并描述资源 + +按照设计,容器往往会成倍增加。在某些条件下,它们可以快速增加。如果你只能通过 `podman ps`或 `docker ps` 来查看正在运行的容器,这可能会让你不知所措。通过 `kubectl get` 和 `kubectl describe`,你可以获得关于哪些 pod 正在运行以及它们正在处理的容器的信息。更重要的是,你可以通过使用 `--namespace` 或 `name` 或 `--selector`等选项,只获得你需要的信息。 + +`get` 子命令不仅仅对 pod 和容器有用。它有关于节点、命名空间、部署、服务和复制的信息。 + +### 2\. 创建资源 + +如果你只通过类似 OpenShift、OKD 或 Kubernetes 提供的 Web 用户界面(UI)创建过部署,但你想从 Linux 终端控制你的集群,那么可以使用 `kubectl create`。`kubectl create` 命令并不只是实例化一个新的应用部署。Kubernetes 中还有很多其他组件可以创建,比如服务、配额和 [CronJob][3]。 + +Kubernetes 中的 CronJob 可以创建一个临时的 pod,用来在你选择的时间表上执行一些任务。它们并不难设置。下面是一个 CronJob,让一个 BusyBox 镜像每分钟响应 “hello world”。 + + +``` +$ kubectl create cronjob \ +hello-world \ +\--image=busybox \ +\--schedule="*/1 * * * *" -- echo "hello world" +``` + +### 3\. 编辑文件 + +你可能了解 Kubernetes 中的对象都有相应的配置文件,但在文件系统中查找相应的文件可能很麻烦。有了 `kubectl edit`,你可以把注意力放在对象上,而不是定义它们的文件上。你可以让 `kubectl` 为你找到并打开文件(它遵循 `KUBE_EDITOR` 环境变量,所以你可以把编辑器设置成你喜欢的)。 + + +``` +$ KUBE_EDITOR=emacs \ +kubectl edit cronjob/hello-world +``` + +### 4\. 容器之间的交换文件 + +初次接触容器的人往往对他们直接无法访问的共享系统的概念感到困惑。他们可能会在容器引擎或 kubectl 中了解到 `exec` 选项,但当他们不能从容器中获取文件或将文件放入容器中时,容器仍然会显得不透明。使用 `kubectl cp` 命令,你可以把容器当做远程服务器,使复制文件到容器或从容器复制文件不比 SSH 命令更复杂: + + +``` +`$ kubectl cp foo my-pod:/tmp` +``` + +### 5\. 应用更改 + +对 Kubernetes 对象进行修改,可以在任何时候通过 `kubectl apply` 命令完成。你所要做的就是将该命令指向一个配置文件: + + +``` +`$ kubectl apply -f ./mypod.json` +``` + +类似于运行 Ansible playbook 或 Bash 脚本,`apply` 使得快速“导入”设置到运行中的 Kubernetes 实例很容易。例如,GitOps 工具 [ArgoCD][4] 由于 `apply` 子命令,安装起来出奇地简单: + + +``` +$ kubectl create namespace argocd +$ kubectl apply -n argocd \ +-f +``` + +### 使用 kubectl + +Kubectl 是一个强大的工具,由于它是一个终端命令,它可以写成脚本,并以许多 Web UI 无法实现的方式使用。学习 kubectl 是进一步了解 Kubernetes、容器、pod 以及围绕这些重要的云计算创新的所有技术的一个好方法。[下载我们的 kubectl 速查表][5],以获得快速参考,其中包括命令示例,以帮助你学习,并在你成为专家后提醒你注意细节。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/21/7/kubectl + +作者:[Alan Smithee][a] +选题:[lujun9972][b] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/alansmithee +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/ship_captain_devops_kubernetes_steer.png?itok=LAHfIpek (Ship captain sailing the Kubernetes seas) +[2]: https://opensource.com/article/20/11/orchestration-vs-automation +[3]: https://opensource.com/article/20/11/kubernetes-jobs-cronjobs +[4]: https://argoproj.github.io/argo-cd/ +[5]: https://opensource.com/downloads/kubectl-cheat-sheet