이미 aws에 리소스가 생성되어 있을 때 이 리소스 정보를 가져올 수 있다.
https://docs.crossplane.io/latest/guides/import-existing-resources/
Crossplane Docs · v1.16 · Import Existing Resources
If you have resources that are already provisioned in a Provider, you can import them as managed resources and let Crossplane manage them. A managed resource’s managementPolicies field enables …
docs.crossplane.io
import하는 방식에는 observe가 있고 실제 import하는 방식이 있는데 observe는 리소스를 변경, 삭제가 불가능하고 import는 실제 리소스가 변경되니 주의해야 한다.
AWS에 생성되어 있는 ec2를 살펴보자.
observe_ec2.yaml 파일을 만들고 아래 내용을 넣는다.
apiVersion: ec2.aws.upbound.io/v1beta1
kind: Instance
metadata:
annotations:
crossplane.io/external-name: i-00446c18a772df57e # 인스턴스 ID
name: joo-observe-ec2 # crossplane 리소스 이름
spec:
managementPolicies: ["Observe"] # observe 옵션 설정
forProvider:
region: "us-east-1" # 리전
providerConfigRef:
name: aaa
apply 명령어로 리소스를 만들고 get -o yaml 명령어로 내용을 볼 수 있다.
kubectl --kubeconfig=[config 경로] apply -f observe_ec2.yaml
이 명령어가 귀찮으면 LENS라는 프로그램을 깔면 된다. 엄청 좋다. 강추!
yaml 파일명이 아니라 생성한 리소스 이름을 넣어야 한다.
kubectl --kubeconfig=[config 경로] get instances.ec2.aws.upbound.io joo-observe-ec2 -o yaml
내용이 엄청 나오는데 대충 status의 atProvider 부분을 보면 된다.
status:
atProvider:
ami: ami-0bb84b8ffd87024d8
arn: arn:aws:ec2:us-east-1:841330598838:instance/i-08140133f9bd07bcb
associatePublicIpAddress: true
availabilityZone: us-east-1a
capacityReservationSpecification:
- capacityReservationPreference: open
cpuCoreCount: 1
cpuOptions:
- amdSevSnp: ""
coreCount: 1
threadsPerCore: 1
cpuThreadsPerCore: 1
creditSpecification:
- cpuCredits: standard
disableApiStop: false
disableApiTermination: false
AWS 콘솔에 있는 키 페어 observe
metadata - annotations - external-name에 observe하려는 AWS 콘솔 이름을 넣는다.
apiVersion: ec2.aws.upbound.io/v1beta1
kind: KeyPair
metadata:
name: joo-observe-keypair # Crossplane에서 사용할 리소스 이름
annotations:
crossplane.io/external-name: joo-virginia-key # AWS 콘솔에 있는 키 이름
spec:
forProvider:
region: us-east-1
providerConfigRef:
name: aaa
managementPolicies: ["Observe"]
'배운 내용 > Kubernetes' 카테고리의 다른 글
[crossplane] 리소스 삭제하기 (0) | 2024.05.17 |
---|---|
[crossplane] internet gateway, route table만들기 (0) | 2024.05.16 |
[crossplane] vpc, subnet 만들기 (0) | 2024.05.16 |
[crossplane] 모든 MetaResource 확인하기 (0) | 2024.05.16 |
쿠버네티스 포트 포워딩 (1) | 2024.04.24 |