LoginSignup
7
4

【kubernetes】aliasでdefault namespaceを変更して毎回同じnamespaceを入力する無駄な時間とオサラバしてハピハピになった件

Last updated at Posted at 2024-05-14

default namespaceをaliasで変更すると無駄な時間とオサラバ出来ます。

実践

echo "alias <ALIAS>='kubectl -n <NAMESPACE>'" >> ~/.zshrc
source ~/.zshrc

設定するとこんなかんじに実行できるようになります

~
❯ k get po
No resources found in default namespace.

~
❯ alias k='kubectl -n <NAMESPACE>' >> ~/.zshrc

~
❯ source ~/.zshrc

~
❯ k get po
NAME                                                   READY   STATUS      RESTARTS   AGE
xxxx-xxxxxx-xxxx                                       1/1     Running     0          7h10m
xxxx-xxxxxx-xxxx                                       1/1     Running     0          7h11m

↓これでdefault namespaceを変更してもいいんだけど、contextごとに設定する必要があるので
複数contextを使っている方はちょっとめんどくさいです。

kubectl config set-context --current --namespace=<NAMESPACE>

皆んなもハピハピになろう! :smirk_cat:

余談

最初記事に >> ~/.zshrc じゃなくて > ~/.zshrc って書いてあって、試しに実行したらzshrcの設定が吹き飛んでアンハピハピした

.zprofileでbackupを取る様にしました。
シェル起動時に一度だけ設定を保存します。

mkdir ~/backup
.zprofile
cp ~/.zshrc ~/backup/.zshrc_backup

一安心だね :star:

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4