-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform, K8s Pod 등 ENV/CONFIGURE 주입 구현 #4
Comments
사전 지식 (개념)전체 내용의 출처 : https://kim-dragon.tistory.com/279 IRSA란?
serviceaccount는 AWS의 자원이 아닌데 어떻게 IAM Role을 할당할 수 있는 걸까요?
serviceaccount란?
OIDC란?
순서
IRSA 사용 해보기아래와 같은 작업이 필요합니다.
|
How to do 가이드를 따라 해보기 (By Terraform)총 작업 시간 4시간
terraform 을 통해 CSI-Driver 설치resource "helm_release" "secrets-store-csi-driver" {
chart = "secrets-store-csi-driver"
name = "csi-secrets-store"
namespace = "kube-system"
repository = "https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts"
set {
name = "syncSecret.enabled"
value = "true"
}
}
resource "helm_release" "secrets-store-csi-driver-provider-aws" {
chart = "secrets-store-csi-driver-provider-aws"
name = "secrets-provider-aws"
namespace = "kube-system"
repository = "https://aws.github.io/secrets-store-csi-driver-provider-aws"
} 왜 Terraform 을 사용하는가?그냥
어떤 리소스가 낭비되는가?
아래와 같이 직접 명령어를 통해 확인해야 한다
$ helm list -n=kube-system
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
csi-secrets-store kube-system 1 2023-09-08 13:41:47.163856656 +0000 UTC deployed secrets-store-csi-driver-1.3.4 1.3.4
secrets-provider-aws kube-system 1 2023-09-08 13:42:45.440840482 +0000 UTC deployed secrets-store-csi-driver-provider-aws-0.3.4 Terraform으로 Secret Manager Group을 생성한다.module "secrets_manager" {
source = "terraform-aws-modules/secrets-manager/aws"
name_prefix = "development/ticketing-backend"
ignore_secret_changes = true
secret_string = jsonencode({
MYSQL_PASSWORD = ""
PORT: ""
MYSQL_HOST: ""
MYSQL_PORT: ""
MYSQL_USERNAME: ""
MYSQL_SCHEMA: ""
JWT_SECRET: ""
JWT_EXPIRATION_HOURS: ""
JWT_ISSUER: ""
})
} 해당 Secret Manager Group을 읽을 수 있는 Iam Policy 생성module "secrets_manager_access_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
name = "secrets-manager-access-policy"
create_policy = true
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
]
Effect = "Allow"
Resource = [
module.secrets_manager.secret_arn
]
}
]
})
} 해당 IAM Policy를 통해 Service Account 생성어떻게 '연결' 또는 '생성'을 할 수 있을까?
resource "kubernetes_service_account" "backend_account" {
metadata {
name = "ticketing-backend-account"
namespace = "default"
annotations = {
"eks.amazonaws.com/role-arn" = module.iam_eks_role.iam_role_arn # 중요
}
}
}
module "iam_eks_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
role_name = "backend-role"
role_policy_arns = {
policy = module.secrets_manager_access_policy.arn
}
oidc_providers = {
backend = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["default:ticketing-backend-account"]
}
}
} $ kubectl describe serviceaccount ticketing-backend-account
Name: ticketing-backend-account
Namespace: default
Labels: <none>
Annotations: eks.amazonaws.com/role-arn: arn:aws:iam::213060417361:role/backend-role
Image pull secrets: <none>
Mountable secrets: <none>
Tokens: <none>
Events: <none> Error: secret "secret-provider" not foundEvents:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Failed 4s (x5 over 42s) kubelet Error: secret "secret-provider" not found
Normal Pulled 4s kubelet Successfully pulled image "213060417361.dkr.ecr.ap-northeast-2.amazonaws.com/ticketing-backend-ecr:latest" in 110.731209ms (110.739094ms including waiting) $ kubectl get secret
NAME TYPE DATA AGE
sh.helm.release.v1.test1.v1 helm.sh/release.v1 1 4h42m
$ kubectl get SecretProviderClass
NAME AGE
secret-provider 7m52s 원인 추정
해결 CSI Driver 설치시 설정값 추가 ...
set {
name = "syncSecret.enabled"
value = "true"
} 정확한 문법 사용 - - name: env_secret
- valueFrom:
- secretKeyRef:
- name: ticketing-secret
- key: MYSQL_PASSWORD
+ - name: MYSQL_USERNAME
+ valueFrom:
+ secretKeyRef:
+ name: ticketing-secret
+ key: MYSQL_USERNAME 완료 |
Description
EKS에 Backend Pod에는 현재 아래와 같은 정보가 필요합니다.
Hashicorp-
Vault
, AWS-Secrets manager
등의 서비스가 있습니다.각 서비스를 비교해서 Terraform-AWS-EKS 환경에 알맞는 서비스를 선택해주세요
레퍼런스
To do
Test Checklist
The text was updated successfully, but these errors were encountered: