์ด๋ฒ 3์ฃผ์ฐจ์๋ 2์ฃผ์ฐจ์ ์ด์ด ๋ก๋๋ฐธ๋ฐ์ค์ปจํธ๋กค๋ฌ์ Ingress(ALB) ์ค์ ์ ๋ํด์ ์ค์ต ํ ์์ ์ด๋ค. ๋ํ ์ฟ ๋ฒ๋คํฐ์ค์ ์คํ ๋ฆฌ์ง๊ฐ ์ด๋ป๊ฒ ๊ตฌ์ฑ๋์ด ์๊ณ , ์ด๋ ํ ์ข ๋ฅ์ ์คํ ๋ฆฌ์ง๊ฐ ์๋์ง ์ดํด ๋ณผ ์์ ์ด๋ค.
ํด๋ฌ์คํฐ ๋ด๋ถ์ ์๋น์ค(ClusterIP, NodePort, Loadbalancer)๋ฅผ ์ธ๋ถ๋ก ๋ ธ์ถ(HTTP/HTTPS) - Web Proxy ์ญํ
kops edit cluster
-----
spec:
certManager:
enabled: true
awsLoadBalancerController:
enabled: true
externalDns:
provider: external-dns
-----
# ์
๋ฐ์ดํธ ์ ์ฉ
kops update cluster --yes && echo && sleep 3 && kops rolling-update cluster
#ingress1.yaml
apiVersion: v1
kind: Namespace
metadata:
name: game-2048
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: game-2048
name: deployment-2048
spec:
selector:
matchLabels:
app.kubernetes.io/name: app-2048
replicas: 2
template:
metadata:
labels:
app.kubernetes.io/name: app-2048
spec:
containers:
- image: public.ecr.aws/l6m2t8p7/docker-2048:latest
imagePullPolicy: Always
name: app-2048
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: game-2048
name: service-2048
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
type: NodePort
selector:
app.kubernetes.io/name: app-2048
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: game-2048
name: ingress-2048
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-2048
port:
number: 80
# ๊ฒ์ ํ๋์ Service, Ingress ๋ฐฐํฌ
kubectl apply -f ~/pkos/3/ingress1.yaml
# ์์ฑ ํ์ธ
kubectl get-all -n game-2048
kubectl get ingress,svc,ep,pod -n game-2048
kubectl get targetgroupbindings -n game-2048
# Ingress ํ์ธ
kubectl describe ingress -n game-2048 ingress-2048
# ๊ฒ์ ์ ์ : ALB ์ฃผ์๋ก ์น ์ ์
kubectl get ingress -n game-2048 ingress-2048 -o jsonpath={.status.loadBalancer.ingress[0].hostname} | awk '{ print "Game URL = http://"$1 }'
# ํ๋ ๋ฐฐํฌ
# date ๋ช
๋ น์ด๋ก ํ์ฌ ์๊ฐ์ 10์ด ๊ฐ๊ฒฉ์ผ๋ก /home/pod-out.txt ํ์ผ์ ์ ์ฅ
cat ~/pkos/3/date-busybox-pod.yaml | yh
kubectl apply -f ~/pkos/3/date-busybox-pod.yaml
# ํ์ผ ํ์ธ
kubectl get pod
kubectl exec busybox -- tail -f /home/pod-out.txt
Sat Jan 28 15:33:11 UTC 2023
Sat Jan 28 15:33:21 UTC 2023
...
# ํ๋ ์ญ์ ํ ๋ค์ ์์ฑ ํ ํ์ผ ์ ๋ณด ํ์ธ > ์ด์ ๊ธฐ๋ก์ด ๋ณด์กด๋์ด ์๋์ง?
kubectl delete pod busybox
kubectl apply -f ~/pkos/3/date-busybox-pod.yaml
kubectl exec busybox -- tail -f /home/pod-out.txt
EBS CSI driver ๋์ : ๋ณผ๋ฅจ ์์ฑ ๋ฐ ํ๋์ ๋ณผ๋ฅจ ์ฐ๊ฒฐ
# kOps ์ค์น ์ ๊ธฐ๋ณธ ๋ฐฐํฌ๋จ
kubectl get pod -n kube-system -l app.kubernetes.io/instance=aws-ebs-csi-driver
# ์คํ ๋ฆฌ์ง ํด๋์ค ํ์ธ
kubectl get sc kops-csi-1-21 kops-ssd-1-17
# PVC, ํ๋ ํ์ธ
kubectl get pvc,pv,pod
kubectl df-pv
# ์ถ๊ฐ๋ EBS ๋ณผ๋ฅจ ์์ธ ์ ๋ณด ํ์ธ
aws ec2 describe-volumes --volume-ids $(kubectl get pv -o jsonpath="{.items[0].spec.csi.volumeHandle}") | jq
# ํ์ผ ๋ด์ฉ ์ถ๊ฐ ์ ์ฅ ํ์ธ
kubectl exec app -- tail -f /data/out.txt
# ํ๋ ๋ด์์ ๋ณผ๋ฅจ ์ ๋ณด ํ์ธ
kubectl exec -it app -- sh -c 'df -hT --type=ext4'
Filesystem Type Size Used Avail Use% Mounted on
/dev/nvme1n1 ext4 3.9G 16M 3.8G 1% /data
/dev/root ext4 124G 4.9G 120G 4% /etc/hosts
# ํ์ฌ pv ์ ์ด๋ฆ์ ๊ธฐ์คํ์ฌ 4G > 10G ๋ก ์ฆ๊ฐ : .spec.resources.requests.storage์ 4Gi ๋ฅผ 10Gi๋ก ๋ณ๊ฒฝ
kubectl get pvc ebs-claim -o jsonpath={.spec.resources.requests.storage} ; echo
kubectl get pvc ebs-claim -o jsonpath={.status.capacity.storage} ; echo
kubectl patch pvc ebs-claim -p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'
# ํ์ธ : ์์น ๋ฐ์์ด ์กฐ๊ธ ๋๋ฆด์ ์๋ค
kubectl exec -it app -- sh -c 'df -hT --type=ext4'
kubectl df-pv
aws ec2 describe-volumes --volume-ids $(kubectl get pv -o jsonpath="{.items[0].spec.csi.volumeHandle}") | jq
์ค๋ ์ท ๊ธฐ๋ฅ ์ ๊ณต!
# kOps ํด๋ฌ์คํฐ ํธ์ง
kops edit cluster
-----
spec:
snapshotController:
enabled: true
# ์
๋ฐ์ดํธ ์ ์ฉ
kops update cluster --yes && sleep 3 && kops rolling-update cluster
kubectl get crd | grep volumesnapshot
[๊ณผ์ 1]: Ingress(with ๋๋ฉ์ธ, ๋จ์ผ ALB ์ฌ์ฉ)์ PATH /mario ๋ mario ๊ฒ์ ์ ์ํ๊ฒ ์ค์ ํ๊ณ , /tetris ๋ tetris ๊ฒ์์ ์ ์ํ๊ฒ ์ค์ ํ๊ณ , SSL ์ ์ฉ ํ ๊ด๋ จ ์ค์ท ์ฌ๋ ค์ฃผ์ธ์.
#ํธ์คํธ ๋๋ฉ์ธ: albweb.burst89.com
#ํ
ํธ๋ฆฌ์ค: albweb.burst89.com/tetris / ๋ง๋ฆฌ์ค: albweb.burst89.com/mario
#์ธ์ฆ์ ์ ๋ณด
#ALB ์ ๋ณด / ๋ฆฌ์ค๋ ์ ๋ณด
#ALB ๋ฆฌ์คํฐ ๋ฃฐ ์ ๋ณด
#TG ์ ๋ณด
๋ฃฐ ๋ด์ฉ์ ์ดํด๋ณด๋ฉด, /mario์ ๊ฒฝ์ฐ k8s-game2048-servicet-ca0f338cf8 TG(mario TG)๋ก ํฌ์๋ฉ์ ํ๊ณ
/tetirs์ ๊ฒฝ์ฐ k8s-game2048-servicem-39ab8f8d1a TG(tetris TG)๋ก ํฌ์๋ฉ์ ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
๊ฐ TG์ ๊ฒฝ์ฐ Pod๊ฐ ๋ค์ด๋ ํธ๋ก ์ฐ๊ฒฐ๋์ด ์๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค.
#Pod ๋ฐ ingress, service ์ ๋ณด
[๊ณผ์ 2]: ํธ์คํธ Path(local-path-provisioner) ์ค์ต ๋ฐ ๋ฌธ์ ์ ํ์ธ๊ณผ ์ฑ๋ฅ ์ธก์ ํ ๊ด๋ จ ์ค์ท ์ฌ๋ ค์ฃผ์ธ์.
#local-path-provisioner ๋ฐฐํฌ(ํ์ฌ Node1์ Pod ์์ฑ)
#ํ๋๊ฐ ๋ฐฐํฌ๋ ์์ปค๋
ธ๋ drainํด์ ๋ฌธ์ ํ์ธ
1. ์์ปค๋
ธ๋ ๋ณ์ ์ง์
2. Pod draing
3. ์ํํ์ธ
4. local-path ์คํ ๋ฆฌ์งํด๋์ค์์ ์์ฑ๋๋ PV ์ Node Affinity ์ค์ ํ์ธ
5. ํ๋๊ฐ ๋ฐฐํฌ๋ ์์ปค๋
ธ๋์ ์ฅ์ ์ ์ง ๋ณด์๋ฅผ ์๋ฃ ํ uncordon ์ ์ ์ํ๋ก ์๋ณต Failback
6. ๋ฐ์ดํฐ ํ์ธ
#์ฑ๋ฅ์ธก์
1. Read IOPS 3000 ํ์ธ
2. Write IOPS 3000 ํ์ธ
[๊ณผ์ 3]: AWS EBS๋ฅผ PVC๋ก ์ฌ์ฉ ํ ์จ๋ผ์ธ ๋ณผ๋ฅจ ์ฆ๊ฐ ํ ๊ด๋ จ ์ค์ท ์ฌ๋ ค์ฃผ์ธ์.
#ํ์ฌ ์ ์ฉ๋ PVC ์ฉ๋ ํ์ธ(4Gi)
#AWS console์์ ์์ฑ๋ 4Gi ๋ณผ๋ฅจ์ ํ์ธ ํ ์ ์์.
#์จ๋ผ์ธ ์์์ ๋ณผ๋ฅจ ํ์ฅ์ ํ ์ ์๋ ์ด์ ๋ ์คํ ๋ฆฌ์ง ํด๋์ค๊ฐ ๋ณผ๋ฅจ ํ์ฅ ๊ธฐ๋ฅ์ ์ ๊ณตํ๊ธฐ ๋๋ฌธ.
#k edit pvc ebs-claim์ผ๋ก ์คํ ๋ณ๊ฒฝ(30Gi)
#30Gi ๋ณ๊ฒฝ ํ์ธ
[๊ณผ์ 4]: AWS Volume SnapShots ์ค์ต ํ ๊ด๋ จ ์ค์ท ์ฌ๋ ค์ฃผ์ธ์.
#์ค๋
์ท ์ปจํธ๋กค๋ฌ ์ค์น ํ์ธ
#์ค๋
์ท ํด๋์ค ์์ฑ ๋ฐ ํ์ธ
#์์ฑ
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-ebs-csi-driver/master/examples/kubernetes/snapshot/manifests/classes/snapshotclass.yaml
#ํ์ธ
#์ค๋
์ท ์์ฑ(์์ฑํ ๋ณผ๋ฅจ์ค๋
์ทํด๋์ค์, ์ค๋
์ท์ ์งํ ํ pvc๋ช
์์ฑ)
#์ค๋
์ท ์์ฑ ํ์ธ
#์ฅ์ ๋ฐ์(pvc, pod ์ญ์ ) / Pod ๋ฐ pvc, ์์ฑ๋ ๋ณผ๋ฅจ์ด ์กด์ฌํ์ง ์์.
#์ค๋
์ท ๋ณต์
#pv,pvc, pod ์์ฑ ๋ฐ pv bound ํ์ธ!!
์ด๋ฒ 3์ฃผ์ฐจ ์คํฐ๋์์๋ ingress์ ์ฟ ๋ฒ๋คํฐ์ค ์คํ ๋ฆฌ์ง์ ๋ํด์ ํ์ต์ ํ์๋ค.
์ด๋ฒ ์ฃผ์ฐจ ๊ณผ์ 1๋ฒ์ ํด๊ฒฐํ๋๋ผ ๊ฑฐ์ ์ฃผ์ค ๋ด๋ด ์๋ํ๋๊ฑฐ ๊ฐ๋ค.... ๋คํ์ด ์คํฐ๋๋ฅผ ๊ฐ์ด ํ์๋ ๊ฐ์ฌ๋ฏผ๋๊ป์ ์กฐ๊ธ ๋์์ ์ฃผ์
์ ํด๊ฒฐ ํ ์ ์์๋ค..
์ ์ ์คํฐ๋๊ฐ ์ด๋ ค์ ์ง๋๊ฑฐ ๊ฐ๋ค... !! ๊ทธ๋๋ ๊ผญ ์์ฃผ ํ ์ ์๋๋ก ๋ ์ด์ฌํ ํด์ผ๊ฒ ๋ค!