0
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 1 year has passed since last update.

EC2 - EKS Cluster連携方法(忘備録)

Last updated at Posted at 2023-08-09

概要

下記ののリンクの手順に従い、できなかった場合、kubeconfigファイルを手動で編集する

  • 例)会社のSSOの設定により、EC2(デプロイ専用)からEKS Clusterに連携できなかった場合、下記のエラーになる
[ec2-user@ip-XX-XX-XX-XX ~]# aws eks update-kubeconfig --region ap-northeast-1 --name <クラスター名>

An error occurred (AccessDeniedException) when calling the DescribeCluster operation: User: arn:aws:sts::1111111111111:assumed-role/AWSReservedSSO_XXXXXXXX_xxxxxxxxxxxxxxxx/xxxxx is not authorized to perform: eks:DescribeCluster on resource: arn:aws:eks:ap-northeast-1:xxxxxxxxxxxx:cluster/<クラスター名> with an explicit deny
  • 上記のエラーは命令語を叩くEC2に、IAMeks:DescribeClusterを追加しても解決できなかった

回避方法

  • .kube/configを作成すること
cd ~
mkdir .kube
cd .kube
vi config
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: <クラスター画面の認証機関>
    server: <クラスター画面のAPI サーバーエンドポイント>
  name: <クラスター画面の ARN>
contexts:
- context:
    cluster: <クラスター画面の ARN>
    user: <クラスター画面の ARN>
  name: <クラスター画面の ARN>
current-context: <クラスター画面の ARN>
kind: Config
preferences: {}
users:
- name: <クラスター画面の ARN>
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - --region
      - ap-northeast-1
      - eks
      - get-token
      - --cluster-name
      - <クラスター名>
      command: aws

対応結果

  • EC2からk8sの命令語を叩けるようになる
[ec2-user@ip-XX-XX-XX-XX ~]$ kubectl run nginx --image nginx
pod/nginx created
[ec2-user@ip-XX-XX-XX-XX ~]$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          10s
  • EKSクラスター画面で、nginxPodが作成されたことを確認する
0
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
0
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?