3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS CLI v2 (awscliv2.zip) でkubectlを使ってみる

Last updated at Posted at 2020-02-20

目的

AWS CLI v2をインストールして、EKS上の情報をkubectl get svcで取得できるようにする。

背景

AWS CLI v2でkubectlが使えない?ということがあったので、実際にやってみる。

環境

  • mac os : Mojave 10.14.16
  • 現在のawscli バージョン: aws-cli/1.16.292

AWS CLI v2をインストールする

AWS公式手順にしたがって作業する。

まずは以下のコマンドでインストールし、awscliv2.zipファイルとして保存する。

curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-macos.zip" -o "awscliv2.zip"

保存したzipファイルを解凍する。

unzip awscliv2.zip

上記でawsというディレクトリが作成されるので、インストールコマンドを実行する。

sudo ./aws/install

パスワードを入力し、You can now run: /usr/local/bin/aws2 --version と返って来ればOK。
バージョンを確認してみる。

hoge:~ fuga$ aws2 --version
aws-cli/2.0.0dev4 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev3

保存されたパスも確認してみる。

hoge:~ fuga$ which aws2
/usr/local/bin/aws2

これでkubectl get svcをすると普通に実行できる。

hoge:~ fuga$ vim ~/.kube/config
hoge:~ fuga$ kubectl get svc
NAME              TYPE           CLUSTER-IP      EXTERNAL-IP                                                                    PORT(S)        AGE
kubernetes        ClusterIP      xxx.xx.x.x      <none>                                                                         443/TCP        88d

AWS CLI v1がまだインストールされてる状態だったことを思い出したので、
v1をアンインストールしてもう一回実行してみると

hoge:~ fuga$ kubectl get svc
Unable to connect to the server: getting credentials: exec: exec: "aws": executable file not found in $PATH

取得できなかった。

kubectlを使えるようにする

先ほどのエラーに
getting credentials: exec: exec: "aws": executable file not found in $PATH
と出力されていたので、awsとどこかに書いているのか、、?と思い、kubeconfigを確認してみる。

hoge:~ fuga$ kubectl config view
- name: arn:aws:eks:us-west-2:xxxxxxxxxx:cluster/hoge-eks-cluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: aws
      env:
      - name: AWS_PROFILE
        value: fuga

commandで使用するコマンドを指定しているが、awsと記述されている。
AWS CLI v2はaws2と実行するので、これをaws2に修正する。

hoge:~ fuga$ kubectl config view
- name: arn:aws:eks:us-west-2:xxxxxxxxxx:cluster/hoge-eks-cluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: aws2
      env:
      - name: AWS_PROFILE
        value: fuga

kubectl get svcを実行してみると

hoge:~ fuga$ vim ~/.kube/config
hoge:~ fuga$ kubectl get svc
NAME              TYPE           CLUSTER-IP      EXTERNAL-IP                                                                    PORT(S)        AGE
kubernetes        ClusterIP      xxx.xx.x.x      <none>                                                                         443/TCP        88d

ちゃんと取得できるようになった。

その他わかったこと

  • 上記の手順でインストールした場合は、awscli v1と共存させる形になる。AWS CLI v1のパスは/usr/local/bin/aws。

  • homebrewでのインストールも可能。brew install awscliで、AWS CLI v2がインストールされる。

参考

▼以下AWS公式ドキュメント
Linux または macOS での AWS CLI バージョン 2 のインストール
重要な変更 – AWS CLI バージョン 1 からバージョン 2 移行

3
0
1

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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?