25๋ ๋ AWS EKS Hands-on Study ์คํฐ๋ ์ ๋ฆฌ ๋ด์ฉ์ ๋๋ค.
EFS
Amazon EFS(Amazon Elastic File System)๋ AWS์์ ์ ๊ณตํ๋ ํด๋ผ์ฐ๋ ๊ธฐ๋ฐ์ ํ์ผ ์คํ ๋ฆฌ์ง ์๋น์ค๋ก ec2, eks์์ ๋์์ ์ ๊ทผ ๊ฐ๋ฅํ ๊ณต์ ํด๋์ด๋ค. ํน์ ์๋ฒ์์ ํ์ผ์ ์์ฑํ๊ณ ๊ณต์ ๋ฅผ ํด์ผ ํ๋ ์ํฉ์ผ ๋ nfs์ฒ๋ผ ์ฐ๋ ๊ฒ์ aws์์ ์๋น์ค ํํ๋ก ์ ๊ณตํ๋ ๊ฒ์ด๋ผ๊ณ ๋ณผ ์ ์๋ค.
sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport 192.168.1.134:/ /mnt/myefs
[root@operator-host ~]# findmnt -t nfs4
TARGET SOURCE FSTYPE OPTIONS
/mnt/myefs 192.168.1.134:/ nfs4 rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,timeo=600,retrans=2,sec=sy
[root@operator-host ~]# nfsstat
Client rpc stats:
calls retrans authrefrsh
18 0 18
Client nfs v4:
null read write commit open open_conf
3 16% 0 0% 0 0% 0 0% 0 0% 0 0%
open_noat open_dgrd close setattr fsinfo renew
0 0% 0 0% 0 0% 0 0% 2 11% 0 0%
setclntid confirm lock lockt locku access
0 0% 0 0% 0 0% 0 0% 0 0% 0 0%
getattr lookup lookup_root remove rename link
1 5% 0 0% 1 5% 0 0% 0 0% 0 0%
symlink create pathconf statfs readlink readdir
0 0% 0 0% 1 5% 1 5% 0 0% 0 0%
server_caps delegreturn getacl setacl fs_locations rel_lkowner
3 16% 0 0% 0 0% 0 0% 0 0% 0 0%
secinfo exchange_id create_ses destroy_ses sequence get_lease_t
0 0% 0 0% 2 11% 1 5% 0 0% 1 5%
reclaim_comp layoutget getdevinfo layoutcommit layoutreturn getdevlist
0 0% 1 5% 0 0% 0 0% 0 0% 0 0%
(null)
1 5%
# ๋ฐ์ดํฐ ์์ฑ ํ
[root@operator-host ~]# vi /mnt/myefs/test.txt
[root@operator-host ~]# nfsstat
Client rpc stats:
calls retrans authrefrsh
39 0 39
Client nfs v4:
null read write commit open open_conf
3 7% 0 0% 2 5% 0 0% 6 15% 0 0%
open_noat open_dgrd close setattr fsinfo renew
0 0% 0 0% 4 10% 1 2% 2 5% 0 0%
setclntid confirm lock lockt locku access
0 0% 0 0% 0 0% 0 0% 0 0% 1 2%
getattr lookup lookup_root remove rename link
3 7% 2 5% 1 2% 3 7% 0 0% 0 0%
symlink create pathconf statfs readlink readdir
0 0% 0 0% 1 2% 1 2% 0 0% 0 0%
server_caps delegreturn getacl setacl fs_locations rel_lkowner
3 7% 0 0% 0 0% 0 0% 0 0% 0 0%
secinfo exchange_id create_ses destroy_ses sequence get_lease_t
0 0% 0 0% 2 5% 1 2% 0 0% 1 2%
reclaim_comp layoutget getdevinfo layoutcommit layoutreturn getdevlist
0 0% 1 2% 0 0% 0 0% 0 0% 0 0%
(null)
1 2%
EFS๋ก ๋ง์ดํธ๋ ๋๋ ํฐ๋ฆฌ์ ๋ฐ์ดํฐ๋ฅผ ์ฐ๊ฒ ๋๋ฉด nfs ํ๋กํ ์ฝ์ ํตํด ํด๋ผ์ด์ธํธ์ EFS ๊ฐ์ ๋ฐ์ดํฐ ์ ์ก์ด ๋ฐ์ํ๋ค.
์ด ๋ nfsstat ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด NFS ์์ฒญ(Call) ์๊ฐ ์ฆ๊ฐํ๋ ๊ฒ์ ํ์ธ ๊ฐ๋ฅํ๋ค.
EFS /etc/fstab ๋ง์ดํธ ์๊ตฌ ์ค์
# /etc/fstab
[EFS IP]:/ /mnt/myefs nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0
[root@operator-host ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 981M 0 981M 0% /dev
tmpfs tmpfs 990M 0 990M 0% /dev/shm
tmpfs tmpfs 990M 432K 989M 1% /run
tmpfs tmpfs 990M 0 990M 0% /sys/fs/cgroup
/dev/xvda1 xfs 30G 3.1G 27G 11% /
tmpfs tmpfs 198M 0 198M 0% /run/user/1000
[EFS IP]:/ nfs4 8.0E 0 8.0E 0% /mnt/myefs
[root@operator-host ~]# ls /mnt/myefs/
test.txt
[root@operator-host ~]# reboot
# ์ฌ๋ถํ
์ดํ
[root@operator-host ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 981M 0 981M 0% /dev
tmpfs tmpfs 990M 0 990M 0% /dev/shm
tmpfs tmpfs 990M 432K 989M 1% /run
tmpfs tmpfs 990M 0 990M 0% /sys/fs/cgroup
/dev/xvda1 xfs 30G 3.1G 27G 11% /
[EFS IP]:/ nfs4 8.0E 0 8.0E 0% /mnt/myefs
tmpfs tmpfs 198M 0 198M 0% /run/user/1000
Kube ops view ์ธ์ฆ์ ์ ์ฉํ์ฌ ๋ฐฐํฌํ๊ธฐ
# kube-ops-view ์ค์น
helm repo add geek-cookbook https://geek-cookbook.github.io/charts/
helm install kube-ops-view geek-cookbook/kube-ops-view --version 1.2.2 --set service.main.type=ClusterIP --set env.TZ="Asia/Seoul" --namespace kube-system
2์ฃผ์ฐจ์ ์ด์ด์ ์ด๋ฒ์ Kube ops view๋ ํด๋ฌ์คํฐ ip๋ก ํด๋ฌ์คํฐ ๋ด๋ถ์์๋ง ์ ๊ทผ ๊ฐ๋ฅํ๊ฒํ๋ค.
# AWS ๋ก๋๋ฐธ๋ฐ์ ์ปจํธ๋กค๋ฌ
helm repo add eks https://aws.github.io/eks-charts
helm repo update
kubectl get sa -n kube-system aws-load-balancer-controller
helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system \
--set clusterName=$CLUSTER_NAME \
--set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller
AWS ๋ก๋๋ฐธ๋ฐ์๋ฅผ ์ฌ์ฉํ์ฌ ์ธ๋ถ์์ ์ฟ ๋ฒ๋คํฐ์ค์ ์ ๊ทผ ๊ฐ๋ฅํ๊ฒ ํ๋ค.
๋ค์ ์์ ์ ํ๊ธฐ์ Route 53์์ ๋๋ฉ์ธ์ ์์ฑํ๊ณ , ACM์์ ์ธ์ฆ์ ์์ฒญ์ ํตํด ์ธ์ฆ์๋ฅผ ์์ฑํ๊ณ R53 ๋๋ฉ์ธ ๋ ์ฝ๋๋ฅผ ์์ฑํ์ฌ CNAME์ด ์ถ๊ฐ๋์๋์ง ํ์ธํ๋ค.
# ExternalDNS
MyDomain="๋ด ๋๋ฉ์ธ"
MyDnzHostedZoneId=$(aws route53 list-hosted-zones-by-name --dns-name "$MyDomain." --query "HostedZones[0].Id" --output text)
curl -s https://raw.githubusercontent.com/gasida/PKOS/main/aews/externaldns.yaml | MyDomain=$MyDomain MyDnzHostedZoneId=$MyDnzHostedZoneId envsubst | kubectl apply -f -
# ์ฌ์ฉ ๋ฆฌ์ ์ ์ธ์ฆ์ ARN ํ์ธ
CERT_ARN=$(aws acm list-certificates --query 'CertificateSummaryList[].CertificateArn[]' --output text)
echo $CERT_ARN
# kubeopsview ์ฉ Ingress ์ค์ : group ์ค์ ์ผ๋ก 1๋์ ALB๋ฅผ ์ฌ๋ฌ๊ฐ์ ingress ์์ ๊ณต์ฉ ์ฌ์ฉ
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/certificate-arn: $CERT_ARN
alb.ingress.kubernetes.io/group.name: study
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
alb.ingress.kubernetes.io/load-balancer-name: myeks-ingress-alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/ssl-redirect: "443"
alb.ingress.kubernetes.io/success-codes: 200-399
alb.ingress.kubernetes.io/target-type: ip
labels:
app.kubernetes.io/name: kubeopsview
name: kubeopsview
namespace: kube-system
spec:
ingressClassName: alb
rules:
- host: kubeopsview.$MyDomain
http:
paths:
- backend:
service:
name: kube-ops-view
port:
number: 8080
path: /
pathType: Prefix
EOF
์ฟ ๋ฒ๋คํฐ์ค์์ ๋๋ฉ์ธ๊ณผ EKS์ ์ธ๊ทธ๋ ์ค๋ฅผ ์ฐ๊ฒฐํ๋ ExternalDNS๋ฅผ ํตํด R53์์ ๋๋ฉ์ธ์ Hosted Zone ID๋ฅผ ๊ฐ์ ธ์จ๋ค.
๊ทธ๋ฆฌ๊ณ ์์ด๋ ๊ฐ์ ExternalDNS์ ์ ๋ฌํ์ฌ DNS๋ฅผ ๋ฑ๋กํ๋ค.
ALB๋ฅผ ํตํด kube-ops-view๋ฅผ ์ธํฐ๋ท์์ ์ ๊ทผ ๊ฐ๋ฅํ๋๋ก ์ค์ ํ๊ณ , R53์ ํตํด ๋๋ฉ์ธ ๊ธฐ๋ฐ์ผ๋ก ํธ๋ํฝ์ ๋ผ์ฐํ ํ๋ค.
https://kubeopsview.$MyDomain/#scale=1.5 ๋ก ์ ์ ์ฑ๊ณต!