Super Kawaii Cute Cat Kaoani
๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Linux/Kubernetes

[AWS] ELK๋กœ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑํ•˜๊ธฐ

728x90

ELK๋กœ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑํ•˜๊ธฐ


๐Ÿ’ก EKS ๊ตฌ์„ฑ์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๋‚ด์šฉ

      - ํด๋Ÿฌ์Šคํ„ฐ ์ด๋ฆ„

      - ๋ฒ„์ „

      - eksClusterRole

      - VPC/subnet

      - ๋ณด์•ˆ๊ทธ๋ฃน

๐Ÿ’ก CloudFormation

๊ตฌ์„ฑ๋“ค์„ ํ•˜๋‚˜์”ฉ ์„ ํƒํ•˜์—ฌ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์‹œ๊ฐ„, ์žฌ์‚ฌ์šฉ์„ฑ ๋ฉด์—์„œ ๋ถˆํŽธํ•จ์ด ๋งŽ๋‹ค.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” "์„ ์–ธ์  ์–ธ์–ด"๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ IaC ๋„๊ตฌ๋ฅผ ํ†ตํ•ด ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.

๐Ÿ’ก eksctl

eks ๊ตฌ์„ฑ์„ ๊ฐ„๋‹จํžˆ ํ•  ์ˆ˜ ์žˆ๋Š” ๋„๊ตฌ

eksctl์„ ์ด์šฉํ•˜์—ฌ eks ๊ตฌ์„ฑ์„ ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด cloudformation์ด ์ž๋™์œผ๋กœ ์ž‘์„ฑ๋œ๋‹ค. ๊ฐ ์„œ๋น„์Šค์— ์—ฐ๊ฒฐํ•˜์—ฌ ํ•„์š”ํ•œ ์ž์›์„ ์ƒ์„ฑํ•˜๊ณ  ์„œ๋กœ ์—ฐ๊ฒฐํ•œ๋‹ค.

โœ… ์—ญํ•  ์ƒ์„ฑ

  •  IAM > ์—ญํ•  > ์—ญํ•  ์ƒ์„ฑ

EKS - Cluster ์„ ํƒ
์ด๋ฆ„ ์„ค์ •
์ƒ์„ฑ ์™„๋ฃŒ

โœ… ์•ก์„ธ์Šค ํ‚ค ๋งŒ๋“ค๊ธฐ

  •  ์˜ค๋ฅธ์ชฝ ์œ„ ๋‹‰๋„ค์ž„ ํด๋ฆญ ํ›„ ๋ณด์•ˆ ์ž๊ฒฉ ์ฆ๋ช…

 

  •  ์•ก์„ธ์Šค ํ‚ค ๋งŒ๋“ค๊ธฐ

 

  •  ๋ฏธ๋ฆฌ ๋น„๋ฐ€ ์—‘์„ธ์Šค ํ‚ค ์ €์žฅํ•ด๋†“๊ธฐ

โœ… awscli ์„ค์น˜

apt install -y awscli

โœ… aws ์„ค์ •

aws configure

 

AWS Access Key ID [None]: AKIAXYKJQRWGXHIQGBNA

AWS Secret Access Key [None]: ๋น„๋ฐ€ ์—‘์„ธ์Šค ํ‚ค

Default region name [None]: ap-northeast-1

Default output format [None]: ๊ทธ๋ƒฅ ์—”ํ„ฐ

โœ… vpc ์ •๋ณด ํ™•์ธ

aws ec2 describe-vpcs

โœ… subnet ์ •๋ณด ํ™•์ธ

aws ec2 describe-subnets

โœ… eksctl ์„ค์น˜

curl --silent --location \\
 "<https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$>(uname -s)_amd64.tar.gz" | tar xz -C /tmp
mv /tmp/eksctl /usr/local/bin

โœ… eksctl ๋ช…๋ น์–ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ

eksctl

โœ… eksctl์„ ํ†ตํ•œ ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์ถ•

eksctl create cluster --vpc-public-subnets subnet-0fa78ede6bad79a9e,subnet-0b6558aa5bb7cb2d7,subnet-00bdc4c78386849b6 --name eks-work-cluster1 --region ap-northeast-1 --version 1.23 --nodegroup-name eks-work-nodegroup --node-type t2.small --nodes 2 --nodes-min 2 --nodes-max 4       

 

โ—๏ธ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฒ„์ „ ์—๋Ÿฌ๋œฐ ๋•Œ

2024-02-21 11:49:05 [โœ–]  getting Kubernetes version on EKS cluster: error running `kubectl version`: exit status                              1 (check 'kubectl --kubeconfig=/etc/kubernetes/admin.conf version')
apt autoremove kubectl
curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.23.17/2024-01-04/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
kubectl version --client
aws eks update-kubeconfig --region ap-northeast-1 --name eks-work-cluster1

โœ… CloudFormation

โœ… ec2 ์ธ์Šคํ„ด์Šค

โœ… node ํ™•์ธ

kubectl get node
kubectl get no -o wide

โœ… ๋„์ปค ์žฌ์„ค์น˜

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL <https://download.docker.com/linux/ubuntu/gpg> -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \\
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] <https://download.docker.com/linux/ubuntu> \\
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \\
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

โœ… ํด๋Ÿฌ์Šคํ„ฐ

โœ… ํด๋Ÿฌ์Šคํ„ฐ์˜ ํŒŒ๋“œ ํ™•์ธ

๋งŒ๋“ค์–ด์ง„ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ํด๋ฆญํ•œ ํ›„ ํฌ๋“œ ํ™•์ธํ•˜๊ธฐ

โœ… ns, pod ํ™•์ธ

kubectl get ns
kubectl get pod -n kube-system

โœ… pod ์ƒ์„ฑ

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx-ctn
    image: nginx
    ports:
    - containerPort: 80

nginx_pod.yaml

k apply -f nginx_pod.yaml

โœ… ์™ธ๋ถ€์— ํฌํŠธ ์ž„์‹œ ์˜คํ”ˆ

kubectl port-forward nginx-pod 8888:80

โœ… ํ™•์ธ

728x90