

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# EKS Pod Identity 연결
<a name="pod-identity-associations"></a>

AWS EKS는 클러스터 관리자가 클러스터 외부의 AWS 서비스와 연결하는 데 필요한 IAM 권한을 받도록 Kubernetes 애플리케이션을 구성하기 위해 Pod Identity Association이라는 새로운 향상된 메커니즘을 도입했습니다. 포드 자격 증명 연결은 IRSA를 활용하지만 EKS API를 통해 직접 구성할 수 있으므로 IAM API를 전혀 사용할 필요가 없습니다.

따라서 IAM 역할은 더 이상 [OIDC 공급자](iamserviceaccounts.md#iam-how-works)를 참조할 필요가 없으므로 더 이상 단일 클러스터에 연결되지 않습니다. 즉, 이제 새 클러스터가 생성될 때마다 역할 신뢰 정책을 업데이트할 필요 없이 여러 EKS 클러스터에서 IAM 역할을 사용할 수 있습니다. 따라서 역할 중복이 필요하지 않으며 IRSA를 자동화하는 프로세스가 간소화됩니다.

## 사전 조건
<a name="_prerequisites"></a>

백그라운드에서 포드 자격 증명 연결의 구현은 작업자 노드에서 에이전트를 데몬 세트로 실행하고 있습니다. 클러스터에서 사전 필수 에이전트를 실행하기 위해 EKS는 EKS Pod Identity Agent라는 새로운 추가 기능을 제공합니다. 따라서 포드 자격 증명 연결(일반적으로 및 )을 생성하려면 클러스터에 `eks-pod-identity-agent` 추가 기능이 사전 설치되어 `eksctl`있어야 합니다. 이 추가 기능은 지원되는 다른 추가 기능과 동일한 방식으로 `eksctl`를 사용하여 생성할 수 있습니다.

```
eksctl create addon --cluster my-cluster --name eks-pod-identity-agent
```

또한 포드 자격 증명 연결을 생성할 때 기존 IAM 역할을 사용하는 경우 새로 도입된 EKS 서비스 보안 주체()를 신뢰하도록 역할을 구성해야 합니다`pods.eks.amazonaws.com`. IAM 신뢰 정책의 예는 아래에서 확인할 수 있습니다.

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "pods.eks.amazonaws.com"
            },
            "Action": [
                "sts:AssumeRole",
                "sts:TagSession"
            ]
        }
    ]
}
```

대신 생성 명령에 기존 역할의 ARN을 제공하지 않으면 `eksctl`는 백그라운드에서 ARN을 생성하고 위의 신뢰 정책을 구성합니다.

## 포드 자격 증명 연결 생성
<a name="_creating_pod_identity_associations"></a>

포드 자격 증명 연결을 조작하기 위해 `eksctl`는 아래에 `iam.podIdentityAssociations`다음과 같은 새 필드를 추가했습니다.

```
iam:
  podIdentityAssociations:
  - namespace: <string> #required
    serviceAccountName: <string> #required
    createServiceAccount: true #optional, default is false
    roleARN: <string> #required if none of permissionPolicyARNs, permissionPolicy and wellKnownPolicies is specified. Also, cannot be used together with any of the three other referenced fields.
    roleName: <string> #optional, generated automatically if not provided, ignored if roleARN is provided
    permissionPolicy: {} #optional
    permissionPolicyARNs: [] #optional
    wellKnownPolicies: {} #optional
    permissionsBoundaryARN: <string> #optional
    tags: {} #optional
```

전체 예제는 [pod-identity-associations.yaml을 참조하세요](https://github.com/eksctl-io/eksctl/blob/main/examples/39-pod-identity-association.yaml).

**참고**  
`permissionPolicy`가 인라인 정책 문서로 사용되는 것 외에도 다른 모든 필드에는 CLI 플래그가 있습니다.

다음과 같은 방법으로 포드 자격 증명 연결을 생성할 수 있습니다. 클러스터를 생성하는 동안 원하는 포드 자격 증명 연결을 구성 파일의 일부로 지정하고 실행하여 다음을 수행합니다.

```
eksctl create cluster -f config.yaml
```

구성 파일을 사용한 클러스터 생성 후 예:

```
eksctl create podidentityassociation -f config.yaml
```

CLI 플래그를 사용한 OR 예:

```
eksctl create podidentityassociation \
    --cluster my-cluster \
    --namespace default \
    --service-account-name s3-reader \
    --permission-policy-arns="arn:aws:iam::111122223333:policy/permission-policy-1, arn:aws:iam::111122223333:policy/permission-policy-2" \
    --well-known-policies="autoScaler,externalDNS" \
    --permissions-boundary-arn arn:aws:iam::111122223333:policy/permissions-boundary
```

**참고**  
한 번에 하나의 IAM 역할만 서비스 계정에 연결할 수 있습니다. 따라서 동일한 서비스 계정에 대한 두 번째 포드 자격 증명 연결을 생성하려고 하면 오류가 발생합니다.

## 포드 자격 증명 연결 가져오기
<a name="_fetching_pod_identity_associations"></a>

특정 클러스터에 대한 모든 포드 자격 증명 연결을 검색하려면 다음 명령 중 하나를 실행합니다.

```
eksctl get podidentityassociation -f config.yaml
```

또는

```
eksctl get podidentityassociation --cluster my-cluster
```

또한 지정된 네임스페이스 내에서 포드 자격 증명 연결만 검색하려면 `--namespace` 플래그를 사용합니다. 예:

```
eksctl get podidentityassociation --cluster my-cluster --namespace default
```

마지막으로 특정 K8s 서비스 계정에 해당하는 단일 연결을 검색하려면 위의 명령`--service-account-name`에 대한 도 포함합니다.

```
eksctl get podidentityassociation --cluster my-cluster --namespace default --service-account-name s3-reader
```

## 포드 자격 증명 연결 업데이트
<a name="_updating_pod_identity_associations"></a>

하나 이상의 포드 자격 증명 연결의 IAM 역할을 업데이트하려면 새 `roleARN(s)`를 구성 파일에 전달합니다. 예:

```
iam:
  podIdentityAssociations:
    - namespace: default
      serviceAccountName: s3-reader
      roleARN: new-role-arn-1
    - namespace: dev
      serviceAccountName: app-cache-access
      roleARN: new-role-arn-2
```

및 실행:

```
eksctl update podidentityassociation -f config.yaml
```

OR(단일 연결을 업데이트하는 경우)은 CLI 플래그를 `--role-arn` 통해 새를 전달합니다.

```
eksctl update podidentityassociation --cluster my-cluster --namespace default --service-account-name s3-reader --role-arn new-role-arn
```

## 포드 자격 증명 연결 삭제
<a name="_deleting_pod_identity_associations"></a>

하나 이상의 포드 자격 증명 연결을 삭제하려면 구성 파일에 `namespace(s)` 및 `serviceAccountName(s)`를 전달합니다. 예:

```
iam:
  podIdentityAssociations:
    - namespace: default
      serviceAccountName: s3-reader
    - namespace: dev
      serviceAccountName: app-cache-access
```

및 실행:

```
eksctl delete podidentityassociation -f config.yaml
```

OR(단일 연결을 삭제하려면)은 CLI 플래그를 `--service-account-name` 통해 `--namespace` 및를 전달합니다.

```
eksctl delete podidentityassociation --cluster my-cluster --namespace default --service-account-name s3-reader
```

## 포드 자격 증명 연결에 대한 EKS 추가 기능 지원
<a name="pod-id-support"></a>

EKS 추가 기능은 EKS Pod Identity Associations를 통한 IAM 권한 수신도 지원합니다. 구성 파일은 `addon.podIdentityAssociations`, `addonsConfig.autoApplyPodIdentityAssociations` 및를 구성할 수 있는 세 개의 필드를 표시합니다`addon.useDefaultPodIdentityAssociations`. 를 사용하여 원하는 포드 자격 증명 연결을 명시적으로 구성`addon.podIdentityAssociations`하거나 `addonsConfig.autoApplyPodIdentityAssociations` 또는를 사용하여 권장 포드 자격 증명 구성을 `eksctl` 자동으로 확인(및 적용)할 수 있습니다`addon.useDefaultPodIdentityAssociations`.

**참고**  
모든 EKS 추가 기능이 시작 시 포드 자격 증명 연결을 지원하는 것은 아닙니다. 이 경우 [IRSA 설정을](addons.md#addons-create) 사용하여 필요한 IAM 권한을 계속 제공해야 합니다.

### IAM 권한을 사용하여 추가 기능 생성
<a name="_creating_addons_with_iam_permissions"></a>

IAM 권한이 필요한 추가 기능을 생성할 때 `eksctl`는 먼저 포드 자격 증명 연결 또는 IRSA 설정이 구성 파일의 일부로 명시적으로 구성되어 있는지 확인하고, 구성되어 있는 경우이 중 하나를 사용하여 추가 기능에 대한 권한을 구성합니다. 예:

```
addons:
- name: vpc-cni
  podIdentityAssociations:
  - serviceAccountName: aws-node
    permissionPolicyARNs: ["arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"]
```

및 실행

```
eksctl create addon -f config.yaml
2024-05-13 15:38:58 [ℹ] pod identity associations are set for "vpc-cni" addon; will use these to configure required IAM permissions
```

**참고**  
포드 자격 증명과 IRSA를 동시에 설정하는 것은 허용되지 않으며 검증 오류가 발생합니다.

포드 ID를 지원하는 EKS 추가 기능의 경우는 추가 기능 생성 시 권장 IAM 권한을 자동으로 구성하는 옵션을 `eksctl` 제공합니다. 이는 구성 파일`addonsConfig.autoApplyPodIdentityAssociations: true`에서를 설정하면 가능합니다. 예:

```
addonsConfig:
  autoApplyPodIdentityAssociations: true
# bear in mind that if either pod identity or IRSA configuration is explicitly set in the config file,
# or if the addon does not support pod identities,
# addonsConfig.autoApplyPodIdentityAssociations won't have any effect.
addons:
- name: vpc-cni
```

및 실행

```
eksctl create addon -f config.yaml
2024-05-13 15:38:58 [ℹ] "addonsConfig.autoApplyPodIdentityAssociations" is set to true; will lookup recommended pod identity configuration for "vpc-cni" addon
```

이와 마찬가지로 CLI 플래그를 통해 동일한 작업을 수행할 수 있습니다. 예:

```
eksctl create addon --cluster my-cluster --name vpc-cni --auto-apply-pod-identity-associations
```

권장 IAM 정책과 함께 포드 자격 증명을 사용하도록 기존 추가 기능을 마이그레이션하려면

```
addons:
- name: vpc-cni
  useDefaultPodIdentityAssociations: true
```

```
eksctl update addon -f config.yaml
```

### IAM 권한으로 추가 기능 업데이트
<a name="_updating_addons_with_iam_permissions"></a>

추가 기능을 업데이트할 때를 지정`addon.PodIdentityAssociations`하면 업데이트 작업이 완료된 후 추가 기능의 상태에 대한 단일 실제 소스를 나타냅니다. 백그라운드에서는 원하는 상태를 달성하기 위해 다양한 유형의 작업이 수행됩니다. 즉,
+ 구성 파일에는 있지만 클러스터에는 없는 포드 ID 생성
+ 연결된 IAM 리소스와 함께 구성 파일에서 제거된 기존 포드 ID 삭제
+ 구성 파일에도 있고 IAM 권한 집합이 변경된 기존 포드 자격 증명 업데이트

**참고**  
EKS 추가 기능이 소유한 포드 자격 증명 연결의 수명 주기는 EKS 추가 기능 API에서 직접 처리합니다.

Amazon EKS 추가 기능과 함께 사용되는 연결에는 `eksctl update podidentityassociation` (IAM 권한을 업데이트하기 위해) 또는 `eksctl delete podidentityassociations` (연결을 제거하기 위해)를 사용할 수 없습니다. 대신 `eksctl update addon` 또는 `eksctl delete addon`를 사용해야 합니다.

추가 기능에 대한 초기 포드 자격 증명 구성을 분석하는 것부터 위의 예를 살펴보겠습니다.

```
eksctl get podidentityassociation --cluster my-cluster --namespace opentelemetry-operator-system --output json
[
    {
        ...
        "ServiceAccountName": "adot-col-prom-metrics",
        "RoleARN": "arn:aws:iam::111122223333:role/eksctl-my-cluster-addon-adot-podident-Role1-JwrGA4mn1Ny8",
        # OwnerARN is populated when the pod identity lifecycle is handled by the EKS Addons API
        "OwnerARN": "arn:aws:eks:us-west-2:111122223333:addon/my-cluster/adot/b2c7bb45-4090-bf34-ec78-a2298b8643f6"
    },
    {
        ...
        "ServiceAccountName": "adot-col-otlp-ingest",
        "RoleARN": "arn:aws:iam::111122223333:role/eksctl-my-cluster-addon-adot-podident-Role1-Xc7qVg5fgCqr",
        "OwnerARN": "arn:aws:eks:us-west-2:111122223333:addon/my-cluster/adot/b2c7bb45-4090-bf34-ec78-a2298b8643f6"
    }
]
```

이제 아래 구성을 사용합니다.

```
addons:
- name: adot
  podIdentityAssociations:

  # For the first association, the permissions policy of the role will be updated
  - serviceAccountName: adot-col-prom-metrics
    permissionPolicyARNs:
    #- arn:aws:iam::aws:policy/AmazonPrometheusRemoteWriteAccess
    - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy

  # The second association will be deleted, as it's been removed from the config file
  #- serviceAccountName: adot-col-otlp-ingest
  #  permissionPolicyARNs:
  #  - arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess

  # The third association will be created, as it's been added to the config file
  - serviceAccountName: adot-col-container-logs
    permissionPolicyARNs:
    - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
```

및 실행

```
eksctl update addon -f config.yaml
...
# updating the permission policy for the first association
2024-05-14 13:27:43 [ℹ]  updating IAM resources stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-prom-metrics" for pod identity association "a-reaxk2uz1iknwazwj"
2024-05-14 13:27:44 [ℹ]  waiting for CloudFormation changeset "eksctl-opentelemetry-operator-system-adot-col-prom-metrics-update-1715682463" for stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-prom-metrics"
2024-05-14 13:28:47 [ℹ]  waiting for CloudFormation stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-prom-metrics"
2024-05-14 13:28:47 [ℹ]  updated IAM resources stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-prom-metrics" for "a-reaxk2uz1iknwazwj"
# creating the IAM role for the second association
2024-05-14 13:28:48 [ℹ]  deploying stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-container-logs"
2024-05-14 13:28:48 [ℹ]  waiting for CloudFormation stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-container-logs"
2024-05-14 13:29:19 [ℹ]  waiting for CloudFormation stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-container-logs"
# updating the addon, which handles the pod identity config changes behind the scenes
2024-05-14 13:29:19 [ℹ]  updating addon
# deleting the IAM role for the third association
2024-05-14 13:29:19 [ℹ]  deleting IAM resources for pod identity service account adot-col-otlp-ingest
2024-05-14 13:29:20 [ℹ]  will delete stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-otlp-ingest"
2024-05-14 13:29:20 [ℹ]  waiting for stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-otlp-ingest" to get deleted
2024-05-14 13:29:51 [ℹ]  waiting for CloudFormation stack "eksctl-my-cluster-addon-adot-podidentityrole-adot-col-otlp-ingest"
2024-05-14 13:29:51 [ℹ]  deleted IAM resources for addon adot
```

이제 포드 자격 증명 구성이 올바르게 업데이트되었는지 확인합니다.

```
eksctl get podidentityassociation --cluster my-cluster --output json
[
    {
        ...
        "ServiceAccountName": "adot-col-prom-metrics",
        "RoleARN": "arn:aws:iam::111122223333:role/eksctl-my-cluster-addon-adot-podident-Role1-nQAlp0KktS2A",
        "OwnerARN": "arn:aws:eks:us-west-2:111122223333:addon/my-cluster/adot/1ec7bb63-8c4e-ca0a-f947-310c4b55052e"
    },
    {
        ...
        "ServiceAccountName": "adot-col-otlp-ingest",
        "RoleARN": "arn:aws:iam::111122223333:role/eksctl-my-cluster-addon-adot-podident-Role1-1k1XhAdziGzX",
        "OwnerARN": "arn:aws:eks:us-west-2:111122223333:addon/my-cluster/adot/1ec7bb63-8c4e-ca0a-f947-310c4b55052e"
    }
]
```

추가 기능에서 모든 포드 자격 증명 연결을 제거하려면를 `[]`로 명시적으로 설정해야 `addon.PodIdentityAssociations` 합니다. 예:

```
addons:
- name: vpc-cni
  # omitting the `podIdentityAssociations` field from the config file,
  # instead of explicitly setting it to [], will result in a validation error
  podIdentityAssociations: []
```

및 실행

```
eksctl update addon -f config.yaml
```

### IAM 권한이 있는 추가 기능 삭제
<a name="_deleting_addons_with_iam_permissions"></a>

추가 기능을 삭제하면 추가 기능과 연결된 모든 포드 자격 증명도 제거됩니다. 클러스터를 삭제하면 모든 추가 기능에 대해 동일한 효과가 적용됩니다. 에서 생성한 포드 자격 증명에 대한 모든 IAM 역할은 정상적으로 `eksctl`삭제됩니다.

## 기존 iamserviceaccounts 및 추가 기능을 포드 자격 증명 연결로 마이그레이션
<a name="_migrating_existing_iamserviceaccounts_and_addons_to_pod_identity_associations"></a>

서비스 계정의 기존 IAM 역할을 포드 자격 증명 연결로 마이그레이션하는 `eksctl` utils 명령이 있습니다.

```
eksctl utils migrate-to-pod-identity --cluster my-cluster --approve
```

백그라운드에서 명령은 다음 단계를 적용합니다.
+ 클러스터에서 아직 활성화되지 않은 경우 `eks-pod-identity-agent` 추가 기능 설치
+ iamserviceaccounts와 연결된 모든 IAM 역할 식별
+ 포드 자격 증명 연결을 지원하는 EKS 추가 기능과 연결된 모든 IAM 역할 식별
+ 새 EKS 서비스 보안 주체를 가리키는 신뢰할 수 있는 추가 엔터티를 사용하여 식별된 모든 역할의 IAM 신뢰 정책 업데이트(및 선택적으로 기존 OIDC 공급자 신뢰 관계 제거)
+ iamserviceaccounts와 연결된 필터링된 역할에 대한 포드 자격 증명 연결 생성
+ 포드 ID로 EKS 추가 기능 업데이트(EKS API는 백그라운드에서 포드 ID를 생성함)

`--approve` 플래그 없이 명령을 실행하면 위의 단계를 반영하는 작업 세트로 구성된 계획만 출력됩니다. 예:

```
[ℹ]  (plan) would migrate 2 iamserviceaccount(s) and 2 addon(s) to pod identity association(s) by executing the following tasks
[ℹ]  (plan)

3 sequential tasks: { install eks-pod-identity-agent addon,
    ## tasks for migrating the addons
    2 parallel sub-tasks: {
        2 sequential sub-tasks: {
            update trust policy for owned role "eksctl-my-cluster--Role1-DDuMLoeZ8weD",
            migrate addon aws-ebs-csi-driver to pod identity,
        },
        2 sequential sub-tasks: {
            update trust policy for owned role "eksctl-my-cluster--Role1-xYiPFOVp1aeI",
            migrate addon vpc-cni to pod identity,
        },
    },
    ## tasks for migrating the iamserviceaccounts
    2 parallel sub-tasks: {
        2 sequential sub-tasks: {
            update trust policy for owned role "eksctl-my-cluster--Role1-QLXqHcq9O1AR",
            create pod identity association for service account "default/sa1",
        },
        2 sequential sub-tasks: {
            update trust policy for unowned role "Unowned-Role1",
            create pod identity association for service account "default/sa2",
        },
    }
}
[ℹ]  all tasks were skipped
[!]  no changes were applied, run again with '--approve' to apply the changes
```

기존 OIDC 공급자 신뢰 관계는 항상 EKS 추가 기능과 연결된 IAM 역할에서 제거됩니다. 또한 iamserviceaccounts와 연결된 IAM 역할에서 기존 OIDC 공급자 신뢰 관계를 제거하려면 `--remove-oidc-provider-trust-relationship` 플래그를 사용하여 명령을 실행합니다. 예:

```
eksctl utils migrate-to-pod-identity --cluster my-cluster --approve --remove-oidc-provider-trust-relationship
```

## 교차 계정 포드 자격 증명 지원
<a name="_cross_account_pod_identity_support"></a>

eksctl은 [EKS Pod Identity 교차 계정 액세스를](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies-cross-account-resource-access.html) 지원합니다. 이 기능을 사용하면 EKS 클러스터에서 실행되는 포드가 다른 AWS 계정의 AWS 리소스에 액세스할 수 있습니다.

### 사용법
<a name="_usage"></a>

교차 계정 액세스와 포드 자격 증명 연결을 생성하려면 먼저 소스 AWS 계정(클러스터 사용)에서 대상 AWS 계정(클러스터가 액세스할 수 있는 리소스 사용)으로의 액세스를 허용하는 IAM 역할 및 정책을 설정합니다. 이에 대한 예는 ["Amazon EKS Pod Identity는 교차 계정 액세스를 간소화합니다."를 참조하세요.](https://aws.amazon.com/blogs/containers/amazon-eks-pod-identity-streamlines-cross-account-access/)

각 계정에 IAM 역할이 구성되면 eksctl을 사용하여 포드 자격 증명 연결을 생성합니다.

```
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  # The cluster name and service account name should match the target
  # account policy's trust relationship.
  name: my-cluster
  region: us-west-2
  version: "1.32"

addons:
  - name: vpc-cni
  - name: coredns
  - name: kube-proxy
  - name: eks-pod-identity-agent

iam:
  podIdentityAssociations:
  - namespace: default
    serviceAccountName: demo-app-sa
    createServiceAccount: true
    # The source role in the same account as the cluster
    roleARN: arn:aws:iam::1111111111:role/account-a-role
    # The target role in a different account
    targetRoleARN: arn:aws:iam::2222222222:role/account-b-role
    # Optional: Disable session tags
    disableSessionTags: false

managedNodeGroups:
  - name: my-cluster
    instanceType: m6a.large
    privateNetworking: true
    minSize: 2
    desiredCapacity: 2
    maxSize: 3
```

## 추가 참조
<a name="_further_references"></a>

 [포드 ID에 대한 공식 AWS Userdocs for EKS 추가 기능 지원](https://docs.aws.amazon.com/eks/latest/userguide/add-ons-iam.html) 

 [포드 자격 증명 연결에 대한 공식 AWS 블로그 게시물](https://aws.amazon.com/blogs/aws/amazon-eks-pod-identity-simplifies-iam-permissions-for-applications-on-amazon-eks-clusters/) 

 [포드 자격 증명 연결을 위한 공식 AWS 사용자 설명서](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html) 