電腦如何設置終端設置代理
by Chris Cooney
克里斯·庫尼(Chris Cooney)
如何設置一個嚴肅的Kubernetes終端 (How to set up a serious Kubernetes terminal)
所有k8s書呆子需要的CLI工具 (All the CLI tools a growing k8s nerd needs)
Kubernetes comes pre-packaged with an outstanding CLI. For basic operations, it works wonderfully. Alas, when one needs to do something quickly, complexity increases.
Kubernetes預先打包了出色的CLI。 對于基本操作,它的運行非常出色。 las,當需要快速執行某項操作時,復雜性就會增加。
The Kubernetes community has built all sorts of web based tooling for monitoring your cluster — kube ops view, grafana etc. However, having a fully kitted terminal will rapidly speed up the time it takes to get to the root of an issue. It forms a fundamental part of your Swiss army knife.
Kubernetes社區已經構建了各種基于Web的工具來監視您的集群— kube ops view , grafana等。但是,擁有完整的終端設備將Swift加快解決問題根源的時間。 它構成了瑞士軍刀的基本組成部分。
The following is a very short list of open source tools that I’ve applied to my OSX terminal. When used together, they allow me to skip around my kubernetes cluster, quickly troubleshoot issues, and monitor behaviour. I’ve cut out lots of small little utilities and stuck to the tools that I find myself using every day.
以下是我已應用于OSX終端的開源工具的簡短列表。 一起使用時,它們使我可以跳過kubernetes集群,快速解決問題并監控行為。 我刪除了許多小的實用程序,并堅持使用每天都能使用的工具。
在使用任何工具之前…… (Before any tools…)
Before you go after these tools, I’d strongly recommend installing zsh. It is an outstanding, open source wrapper around the standard OSX terminal. It is more feature rich and intuitive and the plugins you can install are fantastic. Some of these tools listed make the assumption you have ZSH installed.
在使用這些工具之前,我強烈建議您安裝zsh 。 它是圍繞標準OSX終端的出色的開源包裝器。 它具有豐富的功能和直觀的功能,您可以安裝的插件很棒。 列出的其中一些工具假定您已安裝ZSH。
9秒 (k9s)
I’m starting strong. K9s is the momma bear of CLI tools for kubernetes cluster. You can SSH straight into pods with a single key press, view logs, delete resources and more. It provides outstanding access for the most common operations you’ll be performing. This is a staple for any engineer using kubernetes.
我開始堅強。 K9s是用于Kubernetes集群的CLI工具的后盾。 您可以通過一次按鍵直接SSH到pod中,查看日志,刪除資源等等。 它為您將執行的最常見操作提供了出色的訪問權限。 對于使用kubernetes的任何工程師來說,這都是最重要的。
kubectx (kubectx)
But one thing that K9s doesn’t support is switching between various contexts in your kubernetes config. It is very rare that we’ll only have one single cluster. Switching between these is as simple as
但是K9s不支持的一件事是在kubernetes配置中的各種上下文之間切換。 我們只有一個集群是非常罕見的。 這些之間的切換非常簡單
kubectl config use-context my-context
But with this, there are some prerequisites:
但是,這樣做有一些先決條件:
- You need to know the name of the cluster before you run. 在運行之前,您需要知道集群的名稱。
There is another, similar
set-context
command that could trip you up.還有另一個類似的
set-context
命令可以使您崩潰。
kubectx
presents a simpler alternative to this. If you run kubectx
on its own, it will list out all of the contexts in your .kube/config
file. You can then provide the name of the context you’re interested in:
kubectx
提供了一個更簡單的替代方法。 如果您kubectx
運行kubectx
,它將在.kube/config
文件中列出所有上下文。 然后,您可以提供您感興趣的上下文的名稱:
kubectx my-context
No need to remember all the contexts, no need to manually check files and no possibility of getting the wrong command. Nice and simple. Combined with k9s
, this offers a lot of navigability from your CLI with minimal key presses.
無需記住所有上下文,無需手動檢查文件,也無需獲取錯誤的命令。 漂亮又簡單。 與k9s
結合使用k9s
,只需最少的按鍵k9s
,就可以從CLI進行很多導航。
庫本斯 (kubens)
Once you’re flitting around contexts, you may want to dig into a specific namespace. Once again, it’s very common to have more than a few namespaces in your cluster. Well, ahmetb (the gentleman who brought you kubectx
) also put together kubens
. It’s the same as kubectx
, only for namespaces.
一旦在上下文中四處游蕩,您可能想要挖掘特定的名稱空間。 再一次,在集群中擁有多個命名空間是很常見的。 那么, ahmetb (誰把你的紳士kubectx
)也放在一起kubens
。 它與kubectx
相同,僅適用于名稱空間。
kubens kube-system
Now all of your commands run against the kube-system
namespace, by default. You can also run kubens
without anything else to see a list of your namespaces.
現在,默認情況下,所有命令都針對kube-system
名稱空間運行。 您也可以不帶其他任何內容運行kubens
來查看名稱空間列表。
kube-ps1 (kube-ps1)
So, you can switch between contexts and namespaces. But how do you know which one you’re currently aimed at? It’s a pain to keep checking. At the moment, to find out you’d need to run:
因此,您可以在上下文和名稱空間之間切換。 但是,您怎么知道您當前針對的是哪一個呢? 不斷檢查很痛苦。 目前,要找出答案,您需要運行:
kubens
kubectx
kubectl <my-command>
To remove this, ps1
is a zsh plugin that will automatically show you your current context and namespace:
要刪除此問題, ps1
是一個zsh插件,它將自動向您顯示您當前的上下文和名稱空間:
Now you can see which namespace and context you’re pointing out without running a single command. It’s also highly configurable too — you can turn off namespace or context, if you’re only interested in one of them, or you can use kubeoff
to disable the whole thing entirely.
現在,您無需運行任何命令即可查看要指出的名稱空間和上下文。 它也是高度可配置的-如果您只對名稱空間或上下文之一感興趣,則可以將其關閉,也可以使用kubeoff
完全禁用整個對象。
大力水手 (popeye)
Now, onto something a little different. popeye
will run automatic scans of the resources in your repository and highlight clear, obvious problems. This is a very new tool and one that I have found very useful. If you’re looking for some spring cleaning to do in your cluster, starting with popeye
will give you some clear indications of what needs to be fixed.
現在,到一些不同的地方。 popeye
將對存儲庫中的資源進行自動掃描,并突出顯示明顯的明顯問題。 這是一個非常新的工具,我發現它非常有用。 如果您要在集群中進行一些Spring大掃除,那么從popeye
開始將為您提供一些需要修復的明確指示。
船尾 (Stern)
Ever used kubectl logs
? Noticed you can only follow logs from one pod at one time? Well, worry no more! Stern is a tool that allows you to pull the logs from multiple pods, based on a very flexible query.
曾經使用過kubectl logs
嗎? 是否注意到您一次只能跟蹤一個吊艙中的日志? 好吧,不用擔心! Stern是一種工具,可讓您基于非常靈活的查詢從多個Pod中提取日志。
I’m talking regularly about kubernetes, DevOps and much more on my twitter account.
我經常在Twitter帳戶上談論kubernetes,DevOps以及更多內容。
翻譯自: https://www.freecodecamp.org/news/how-to-set-up-a-serious-kubernetes-terminal-dd07cab51cd4/
電腦如何設置終端設置代理