# 1. VSCode 서버 구성하기

## VSCode Server 기반 EKS 실습 환경 구축 가이드

이 문서는 워크샵 환경에서 EKS 실습을 위해 필요한 도구 설치, VPC 및 클러스터 배포 과정을 안내합니다.

***

### 1. 기본 환경 준비

Cloudshell에서 아래 git을 Clone하고, iam user를 생성합니다.&#x20;

* iam user name :&#x20;
* iam user pwd  :&#x20;
* account alias :

```
git clone https://github.com/whchoi98/useful-shell.git
cd ~/useful-shell/
./create_iam_user.sh

```

{% hint style="info" %}
실습 환경을 위해 iam user는 admin 권한이므로 주의를 필요로 합니다 !!!
{% endhint %}

***

### 2 . 관리용 VPC 및 ALB + VSCode Server 배포

신규 생성된 계정과 ID로 접속해서, 다시 Cloudshell을 실행합니다.

관리용 VPC 및 ALB+VSCode 서버를 배포합니다.

* VPC Name : mgmtvpc

```
# Cloudshell에서 GitHub 저장소 복제
git clone https://github.com/whchoi98/ec2_vscode.git
aws cloudformation deploy \
  --template-file "~/ec2_vscode/vscode_secure.yml" \
  --stack-name=mgmtvpc \
  --capabilities CAPABILITY_NAMED_IAM
  
```

* ALB DNS 확인 : 아래 Shell을 실행해서, VSCode에 접속 가능한 URL을 확인합니다.

```
~/ec2_vscode/mgmtvpc_alb1.sh
```

* VSCode에 접속 후 터미널에서 아래 Git을 다시 복제하고, VSCode Server의 패스워드를 신규 입력합니다.

```
git clone https://github.com/whchoi98/ec2_vscode.git
~/ec2_vscode/vscode_pwd.sh

```

* ALB DNS로 재접속하면, 신규 설정된 패스워드를 입력하고 VSCode에 연결합니다.

***

### 3. EKS설치를 위한 도구 세트 설치

* EKS 설치를 위한 도구 세트를 VSCode Server에 설치합니다.

```
mkdir ~/environment/
cd ~/environment/
git clone https://github.com/whchoi98/useful-shell.git
~/environment/useful-shell/c9-tool-set.sh

```

* 추가적으로 EKS 환경 구성을 위한 도구 세트를 VSCode Server에 설치합니다.

```
~/environment/useful-shell/eks_tools.sh
source ~/.bash_profile

```

***

### 4. IAM Role 확인 및 환경변수 설정

* IAM Role이 VSCode Server(EC2)에 적절히 바인딩되었는지 확인합니다.

```
git clone https://github.com/whchoi98/myeks
~/environment/myeks/shell/ide_role_check.sh


```

* EKS 설치 구성을 위한 환경 변수를 설정합니다.

```
~/environment/myeks/shell/set-aws-env.sh

```

***

### 5. KMS (CMK) 생성

* KMS 를 아래 Shell 실행을 통해 구성합니다.

```
~/environment/myeks/shell/kms-setup.sh

```

***

### 6. EKS용 VPC 구성

* EKS 설치를 위한 VPC를 아래 명령어 세트를 통해 실행합니다.

```
cd ~/environment/myeks/
aws cloudformation deploy \
  --stack-name "eksworkshop" \
  --template-file "EKSVPC3AZ.yml" \
  --capabilities CAPABILITY_NAMED_IAM
```

* Cloudformation 이 설치가 완료되면, EKS 설치를 위한 환경 변수를 설정합니다.

```
~/environment/myeks/shell/eks_shell.sh
```

***

### 7. EKS 클러스터 배포 YAML 구성

* EKS 클러스터 배포를 위한 eksctl yaml을 생성합니다.

```
# ~/.bash_profile 로 환경변수 불러오기
source ~/.bash_profile

# eksctl YAML 자동 생성
~/environment/myeks/shell/eksctl_shell.sh
```

* 생성된 eksctl yaml 파일이 정상적으로 구성되었는지 dry-run을 실행합니다.

```
eksctl create cluster --config-file=/home/ec2-user/environment/myeks/eksworkshop.yaml --dry-run
```

***

### 8. EKS 클러스터 배포 (실행)

아래 명령을 실행해서, EKS Cluster를 구성합니다. (15분 정도 소요됩니다.)

```
eksctl create cluster --config-file=/home/ec2-user/environment/myeks/eksworkshop.yaml
```

***

### 9. 정리

| 항목          | 설명                                  |
| ----------- | ----------------------------------- |
| 실습 환경       | VSCode Server on EC2                |
| 주요 스크립트 저장소 | <https://github.com/whchoi98/myeks> |
| VPC 배포      | CloudFormation                      |
| EKS 배포      | eksctl 기반 yaml                      |
| 도구 구성       | kubectl, helm, eksctl, jq, yq 포함    |

***

이제 실습을 위한 EKS 클러스터가 구성 완료되었습니다.
