LoginSignup
1
1

More than 1 year has passed since last update.

ツール インストール

Last updated at Posted at 2020-09-29

概要

  • k8sテスト環境構築
    ツール インストール

構築目次

環境

  • Rancher: v2.6.3
  • kubernetes(Client): v1.22.4
  • kubernetes(Server): v1.22.4

ツール

以下インストール/設定を行う

Name 内容
bash-completion コマンド自動完成(bashの「Tab」キーと同じ)
krew kubectlのプラグイン管理ツール
kubectx 使用contextを簡単に変更
kubens 作業namespaceを簡単に変更

kubectl AutoCompletion 設定

## bash-completion インストール ##
$ sudo apt-get install bash-completion

## 確認(_init_completion is a functionとか何とか出たらOK!!) ##
$ type _init_completion

## Completion スクリプトを「/etc/bash_completion.d」に追加 ##
$ kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl

## 「kubectl」のaliasを使う場合は以下設定追加 ##
$ echo 'alias k=kubectl' >>~/.bashrc
$ echo 'complete -F __start_kubectl k' >>~/.bashrc

## bash reload後、確認 ##
$ kubectl get pod
poddisruptionbudgets.policy        pods                               pods.metrics.k8s.io                
podmonitors.monitoring.coreos.com  podsecuritypolicies.policy         podtemplates 

krew 設定

## 以下コマンド実行で krew インストール ##
(
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
  KREW="krew-${OS}_${ARCH}" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
  tar zxvf "${KREW}.tar.gz" &&
  ./"${KREW}" install krew
)

## PATH追加 ##
$ vi ~/.bashrc
$ cat ~/.bashrc
..........
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
..........

## 確認 ##
$ kubectl krew
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."
..........

kubectx, kubens 設定

※インストール方法はいくつかあるが、ここではkrewを使ってインストール

## kubectx インストール ##
$ kubectl krew install ctx

## kubens インストール ##
$ kubectl krew install ns

確認

  • kubectx

    • サンプルcontext作成
      $ kubectl config set-context ns-kube-system --cluster obi-cluster --namespace=kube-system
    • context変更確認
      ※黄色のcontextが使用中のcontext
      2-1.png
  • kubens
    namespace変更確認
    ※黄色のnamespaceが使用中のnamespace
    2-2.png

1
1
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
1
1