클라우드 개발/쿠버네티스
Spring 프로젝트에서 쿠버네티스 API 사용하기(1) - 계정 생성 및 토큰 추출
채야미
2024. 1. 30. 12:12
참고 : https://coffeewhale.com/apiserver
쿠버네티스 API서버는 정말 그냥 API서버라구욧
쿠버네티스 API서버에 대해서 한층 더 가까워지는 시간을 가져봅시다.
coffeewhale.com
위의 글을 참고하여 작성하였습니다
주의 : 쿠버네티스 최신 버전에서는 Service Account를 생성해도 Secrete이 자동 생성되지 않음 → 시크릿 수동 생성 필요
- Role의 Secrete 생성 및 적용
apiVersion: v1
kind: Secret
metadata:
name: seeku-rest-api
annotations:
kubernetes.io/service-account.name: "my-service-account"
type: kubernetes.io/service-account-token
2. 서비스 어카운트 생성 및 적용
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-service-account
3. 다양한 기능을 api로 사용하기 위해 모든 권한을 가진 ClusterRole 생성 rest-api-full-acces.yml 파일로 저장 및 적용
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: full-access
rules:
- apiGroups: [""]
resources: ["*"]
verbs: ["]
4. 서비스 어카운트와 ClusterRole 바인딩
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: rest-api-full-access
subjects:
- kind: ServiceAccount
name: rest-api
namespace: default
roleRef:
kind: ClusterRole
name: full-access
apiGroup: rbac.authorization.k8s.io
5. 토큰을 추출하고 참고 블로그를 이용하여 api 주소에 토큰 대입
서비스 어카운트의 시크릿에서 토큰을 추출
kubectl create secret generic seeku-rest-api --from-literal=token=YOUR_TOKEN -n default
api 주소를 확인후 curl로 토큰을 대입하여 응답을 확인 하면 완료