1
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 3 years have passed since last update.

kubectl Unable to connect to the server Error

Last updated at Posted at 2022-03-08

OverView

久々にKubernetes(EKS)を弄ったとき、以下のエラーが出ました。

Unable to connect to the server: getting credentials: exec plugin is configured to use API version client.authentication.k8s.io/v1alpha1, plugin returned version client.authentication.k8s.io/v1beta1

その時の対処法です。

追記

eksctlを繰り返すたびにconfigがv1plpha1で設定されるため調べてみました。
Detection of the authenticator credential API version
eksctl のインストール

まとめるとeksctlのバージョンが古いときに発生するようです。

$ eksctl version
0.84.0
### アップデート後
$ eksctl version
0.86.0

0.86にすればOKです。

Environment

Machine : Mac M1
OS : Big Sur 11.2

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:38:33Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"darwin/arm64"}

$ aws --version
aws-cli/2.4.5 Python/3.8.8 Darwin/20.3.0 exe/x86_64 prompt/off

Action

エラー文言からkube configを見てみる

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://hoge.gr7.ap-northeast-1.eks.amazonaws.com
  name: hoge.ap-northeast-1.eksctl.io
contexts:
- context:
    cluster: hoge.ap-northeast-1.eksctl.io
    user: hoge-eks.ap-northeast-1.eksctl.io
  name: hoge-eks.ap-northeast-1.eksctl.io
current-context: hoge-eks.ap-northeast-1.eksctl.io
kind: Config
preferences: {}
users:
- name: hoge.ap-northeast-1.eksctl.io
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - token
      - -i
      - hoge
      command: aws-iam-authenticator
      env:
      - name: AWS_STS_REGIONAL_ENDPOINTS
        value: regional
      - name: AWS_DEFAULT_REGION
        value: ap-northeast-1
      - name: AWS_PROFILE
        value: hoge
      interactiveMode: IfAvailable
      provideClusterInfo: false

この部分です。

  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1

変更します。

vi ~/.kube/config
・・・
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
・・・

確認します。

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
・・・
users:
- name: hoge.ap-northeast-1.eksctl.io
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - token

getコマンドでやってみます。

$ kubectl get pod,svc
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   109m

出来ました。

ご参考まで。

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