Skip to content

Latest commit

ย 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation



Cloudtype



ํด๋ผ์šฐ๋“œํƒ€์ž… ์›จ๋น„๋‚˜ #03
ํด๋ผ์šฐ๋“œํƒ€์ž…, AWS Elastic Kubernetes Service๋ฅผ ํ™œ์šฉํ•œ
๊ฐœ๋ฐœ์ž ํ”Œ๋žซํผ ๊ตฌ์ถ•ํ•˜๊ธฐ

๋ชฉ์ฐจ

๐Ÿ—’๏ธ ์‹ค์Šต ์˜ˆ์ œ ์‚ฌ์–‘

  • Kubernetes(AWS EKS)
    • Engine: v1.25
    • Node: Amazon Linux 2, t3.medium x 2
  • Helm: v3.12.1
  • Calico: v3.25.1
  • Cert Manager: v1.12.0
  • Nginx Ingress Controller: v1.8.1

๐Ÿ–‡๏ธ ์ค€๋น„์‚ฌํ•ญ

๐Ÿงฐ ํ•„์š” ๋„๊ตฌ ์„ค์น˜

AWS CLI

  • AWS CLI ์„ค์น˜

    $ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
    $ sudo installer -pkg AWSCLIV2.pkg -target /
  • AWS ๊ณ„์ • ์„ค์ •

    $ aws configure

kubectl

$ curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.25.9/2023-05-11/bin/darwin/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' >> ~/.zshrc
$ source ~/.zshrc

eksctl

  • macOS

    $ brew tap weaveworks/tap
    $ brew install weaveworks/tap/eksctl
    $ eksctl version
  • Unix

    $ ARCH=amd64    # Apple Silicon(M1/M2) ๋“ฑ ARM ์•„ํ‚คํ…์ฒ˜์ธ ๊ฒฝ์šฐ `ARCH=arm64` ์ž…๋ ฅ
    $ PLATFORM=$(uname -s)_$ARCH
    
    $ curl -sLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"
    
    $ tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz
    
    $ sudo mv /tmp/eksctl /usr/local/bin

Helm

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh

๐Ÿ› ๏ธ EKS ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑํ•˜๊ธฐ

AWS CLI ์„ค์ •

ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ

$ eksctl create cluster \
          --name=cloudtype-test \
          --region=ap-northeast-2 \
          --without-nodegroup

ํ‚คํŽ˜์–ด ์ƒ์„ฑ

  1. EC2 > Network & Security > Key Pairs ๋ฉ”๋‰ด๋กœ ์ง„์ž…
  2. Create key pair ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ณ  ๋‹ค์Œ์˜ ํ•ญ๋ชฉ์„ ํ™•์ธ ํ›„ ํ‚ค๋ฅผ ์ƒ์„ฑ
    • Name: ํ‚คํŽ˜์–ด๋ช…
    • Key pair type: RSA
    • Private key file format: .pem
  3. ํ‚คํŽ˜์–ด ์ƒ์„ฑ์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ๋˜๋ฉด .pem ํ™•์žฅ์ž์˜ ํŒŒ์ผ์ด ๋‹ค์šด๋กœ๋“œ ๋˜๋ฉฐ, ๋ณด์•ˆ์— ์œ ์˜ํ•˜์—ฌ ์•ˆ์ „ํ•œ ์œ„์น˜์— ํŒŒ์ผ ๋ณด๊ด€

๋…ธ๋“œ ๊ทธ๋ฃน ์ƒ์„ฑ

$ eksctl create nodegroup \
                    --cluster=cloudtype-test \
                    --region=ap-northeast-2 \
                    --name=ng-eks-01 \
                    --node-type=t3.medium \
                    --nodes=2 \
                    --nodes-min=2 \
                    --nodes-max=4 \
                    --node-volume-size=20 \
                    --ssh-access \
                    --ssh-public-key=[ํ‚คํŒŒ์ผ๋ช…] \
                    --managed \
                    --asg-access \
                    --external-dns-access \
                    --full-ecr-access \
                    --appmesh-access \
                    --alb-ingress-access 

๋…ธ๋“œ ๊ทธ๋ฃน ์—ญํ•  ๋‚ด ๊ถŒํ•œ ํ™•์ธ

  • ECR ๊ด€๋ จ ํ•„์š” ๊ถŒํ•œ ํ™•์ธ ํ•„์š”
    • ์—ญํ• ๋ช…
      • eksctl-[ํด๋Ÿฌ์Šคํ„ฐ๋ช…]-nodegroup-n-NodeInstanceRole-xxxxxxxxxx
    • ๊ถŒํ•œ
      • AmazonEC2ContainerRegistryReadOnly
      • AmazonEC2ContainerRegistryPowerUser

Cloudtype

โš™๏ธ EKS ํด๋Ÿฌ์Šคํ„ฐ ์„ธํŒ…ํ•˜๊ธฐ

Calico Network Policy Engine add-on ์„ค์น˜

  • Calico ์„ค์น˜

    $ helm repo add projectcalico https://docs.tigera.io/calico/charts
    $ helm repo update
    $ helm install calico projectcalico/tigera-operator \
            --version v3.25.1 \
            --set installation.kubernetesProvider=EKS \
            --namespace tigera-operator \
            --create-namespace
    $ helm -n tigera-operator get values calico
  • Network Policy Engine add-on ์ ์šฉ

    $ kubectl patch clusterrole aws-node \
              --type='json' \
              -p='[{"op": "add", "path": "/rules/-1", "value":{ "apiGroups": [""], "resources": ["pods"], "verbs": ["patch"]}}]' \
              -o yaml
    $ kubectl set env daemonset aws-node -n kube-system ANNOTATE_POD_IP=true
    $ kubectl get po -n calico-system | grep calico-kube-controllers-                   # pod ์ด๋ฆ„์€ ๋‚œ์ˆ˜ ํ˜•ํƒœ๋กœ ํ• ๋‹น๋˜์–ด ๊ฐœ๋ณ„์ ์œผ๋กœ ํ™•์ธ ํ•„์š”
    $ kubectl get pods -n calico-system --no-headers=true \
        | awk '/calico-kube-controllers-/{print $1}' \
        | xargs kubectl delete -n calico-system pod
    $ kubectl get po -n calico-system | grep calico-kube-controllers-                   # ์‚ญ์ œ ํ›„ ์žฌ์ƒ์„ฑ๋œ pod ์ •์ƒ ์ƒํƒœ ํ™•์ธ

Cert Manager ์„ค์น˜

$ helm repo add jetstack https://charts.jetstack.io
$ helm repo update
$ helm install \
      cert-manager jetstack/cert-manager \
      --namespace cert-manager \
      --create-namespace \
      --version v1.12.0 \
      --set installCRDs=true

Nginx Ingress Controller ์„ค์น˜

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/aws/deploy.yaml

Cloudflare ๋„๋ฉ”์ธ ๋ฐ ์ธ์ฆ์„œ ์ ์šฉ

  1. Cloudflare API KEY ๋ฐœ๊ธ‰

    • Cloudflare ๋‚ด ํ”„๋กœํ•„ > API ํ† ํฐ ํŽ˜์ด์ง€ ์ด๋™
    • ํ† ํฐ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ
    • ์˜์—ญ DNS ํŽธ์ง‘ ํ…œํ”Œ๋ฆฟ ์‚ฌ์šฉ ๋ฒ„ํŠผ ํด๋ฆญ
    • ๋‹ค์Œ ์ด๋ฏธ์ง€์™€ ๊ฐ™์ด ์„ธํŒ… ํ›„, ์š”์•ฝ ๊ณ„์† ๋ฒ„ํŠผ ํด๋ฆญ(์˜์—ญ ๋ฆฌ์†Œ์Šค ํ•ญ๋ชฉ์€ ์‚ฌ์šฉํ•  ๋„๋ฉ”์ธ ์„ ํƒ)

      Cloudtype

    • ํด๋ผ์šฐ๋“œํƒ€์ž…๊ณผ ์—ฐ๋™ํ•  ๋„๋ฉ”์ธ ํ™•์ธ ํ›„, ํ† ํฐ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ
  2. ingress-nginx-controller LoadBalancer ์™ธ๋ถ€ IP CNAME ๋ ˆ์ฝ”๋“œ ๋“ฑ๋ก

    • ingress-nginx-controller LoadBalancer ์™ธ๋ถ€ IP(Hostname) ํ™•์ธ

      $ kubectl get svc \
          -n ingress-nginx \
          ingress-nginx-controller \
          -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'  # EKS์˜ ๊ฒฝ์šฐ LoadBalancer์˜ ์™ธ๋ถ€ IP๋ฅผ URL ํ˜•์‹์œผ๋กœ ํ• ๋‹น
    • Cloudflare์—์„œ ์—ฐ๋™ํ•  ๋„๋ฉ”์ธ์˜ ๋Œ€์‹œ๋ณด๋“œ์—์„œ, DNS > ๋ ˆ์ฝ”๋“œ ํŽ˜์ด์ง€ ์ด๋™

    • ๋ ˆ์ฝ”๋“œ ์ถ”๊ฐ€ ๋ฒ„ํŠผ ํด๋ฆญ ํ›„, ๋‹ค์Œ ๋‘ ๊ฐœ์˜ ๋ ˆ์ฝ”๋“œ ์ถ”๊ฐ€

      Cloudtype

      • ์œ ํ˜•: CNAME, ์ด๋ฆ„: *, IPv4 ์ฃผ์†Œ: ์œ„์—์„œ ์กฐํšŒํ•œ LoadBalancer ์™ธ๋ถ€ IP
      • ์œ ํ˜•: CNAME, ์ด๋ฆ„: ํ˜„์žฌ ๋„๋ฉ”์ธ(example.com์ธ ๊ฒฝ์šฐ example.com), IPv4 ์ฃผ์†Œ: ์œ„์—์„œ ์กฐํšŒํ•œ LoadBalancer ์™ธ๋ถ€ IP
  3. Cloudflare API KEY ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋“ฑ๋ก

    $ export CLOUDFLARE_ACME_EMAIL=<Cloudflare ๊ณ„์ • ID>
    $ export CLOUDFLARE_API_TOKEN=<Cloudflare API KEY>
  4. Cluster Issuer / Certificate ์ƒ์„ฑ

    $ cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Namespace
    metadata:
      name: cloudtype
    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: cloudflare-api-token-secret
      namespace: cert-manager
    type: Opaque
    stringData:
      api-token: "${CLOUDFLARE_API_TOKEN}"
    ---
    apiVersion: cert-manager.io/v1
    kind: ClusterIssuer
    metadata:
      name: cloudtype-crt
      namespace: cert-manager
    spec:
      acme:
        email: "${CLOUDFLARE_ACME_EMAIL}"
        server: https://acme-v02.api.letsencrypt.org/directory
        privateKeySecretRef:
          name: cloudtype-crt
        solvers:
          - http01:
              ingress:
                class: nginx
          - dns01:
              cloudflare:
                email: "${CLOUDFLARE_ACME_EMAIL}"
                apiTokenSecretRef:
                  name: cloudflare-api-token-secret
                  key: api-token
            selector:
              dnsZones:
                - [Cloudflare์— ๋“ฑ๋ก๋œ ๋„๋ฉ”์ธ]
    ---
    apiVersion: cert-manager.io/v1
    kind: Certificate
    metadata:
      name: cloudtype-tls
      namespace: cloudtype
    spec:
      dnsNames:
        - "[Cloudflare์— ๋“ฑ๋ก๋œ ๋„๋ฉ”์ธ]"
        - "*.[Cloudflare์— ๋“ฑ๋ก๋œ ๋„๋ฉ”์ธ]"
      issuerRef:
        kind: ClusterIssuer
        name: cloudtype-crt
      secretName: cloudtype-tls
    EOF
  5. Cert Manager Order ์ƒํƒœ ํ™•์ธ

    $ kubectl get order -n cloudtype \
      | awk '/cloudtype-tls-/{print $1}' \
      | xargs kubectl get order -n cloudtype
    • ์ •์ƒ์ ์œผ๋กœ TLS ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ƒํƒœ์ธ์ง€ ํ™•์ธ ํ•„์š”
      • Order์˜ STATE ํ•ญ๋ชฉ ๊ฐ’์ด valid์—ฌ์•ผ ํด๋ผ์šฐ๋“œํƒ€์ž…์—์„œ ๋ฐฐํฌํ•œ ์„œ๋น„์Šค์— ๋Œ€ํ•˜์—ฌ HTTPS ์ธ์ฆ์ด ์ •์ƒ์ ์œผ๋กœ ์ง„ํ–‰
    • Cloudflare DNS์˜ ๋„๋ฉ”์ธ์— ์ธ์ฆ์„œ๊ฐ€ ๋ฐœ๊ธ‰๋˜๊ธฐ ์œ„ํ•œ ์ƒํƒœ๊ฐ€ ๋˜๊ธฐ๊นŒ์ง€ ์•ฝ 30๋ถ„~1์‹œ๊ฐ„ ์†Œ์š”

AWS EBS CSI ์„ค์น˜

  1. ํด๋Ÿฌ์Šคํ„ฐ IAM OIDC ์ œ๊ณต์—…์ฒด ์ƒ์„ฑ

    $ export CLUSTER_NAME=cloudtype-test
    $ OIDC_ID=$(aws eks describe-cluster --name $CLUSTER_NAME --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
    $ aws iam list-open-id-connect-providers | grep $OIDC_ID | cut -d "/" -f4
    $ eksctl utils associate-iam-oidc-provider --cluster $CLUSTER_NAME --approve
  2. EBS CSI ๋“œ๋ผ์ด๋ฒ„ IAM ์—ญํ•  ์ƒ์„ฑ

    $ eksctl create iamserviceaccount \
        --name ebs-csi-controller-sa \
        --namespace kube-system \
        --cluster ${CLUSTER_NAME} \
        --role-name AmazonEKS_EBS_CSI_DriverRole \
        --role-only \
        --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
        --approve
  3. EKS add-on EBS CSI ๋“œ๋ผ์ด๋ฒ„ ์ ์šฉ

    $ export ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text | xargs -L 1)
    $ eksctl create addon \
        --name aws-ebs-csi-driver \
        --cluster ${CLUSTER_NAME} \
        --service-account-role-arn arn:aws:iam::${ACCOUNT_ID}:role/AmazonEKS_EBS_CSI_DriverRole \
        --force
  4. ๊ธฐ์กด Storage Class dafault ํ•ด์ œ

    $ kubectl patch storageclass gp2 -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
  5. ์‹ ๊ทœ Storage Class dafault ์„ค์ •

    $ cat <<EOF | kubectl apply -f -
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: gp3
      annotations:
        storageclass.kubernetes.io/is-default-class: "true"
    allowVolumeExpansion: true
    provisioner: ebs.csi.aws.com
    volumeBindingMode: Immediate
    parameters:
      type: gp3
      allowAutoIOPSPerGBIncrease: 'true'
      encrypted: 'true'
    EOF
  6. PVC ์ƒ์„ฑ ํ…Œ์ŠคํŠธ

    $ cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-test
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: gp3
      resources:
        requests:
          storage: 1Gi
    EOF
  7. PVC ์ƒํƒœ ํ™•์ธ

    $ kubectl get pvc pvc-test
    • PVC์˜ STATUS๊ฐ€ Bound์ธ์ง€ ํ™•์ธ

โ˜๏ธ ํด๋ผ์šฐ๋“œํƒ€์ž… ์—ฐ๋™ํ•˜๊ธฐ

ํด๋ผ์šฐ๋“œํƒ€์ž… ์—์ด์ „ํŠธ ์„ค์น˜ ๋ฐ ํด๋Ÿฌ์Šคํ„ฐ ์ถ”๊ฐ€

  1. ์—์ด์ „ํŠธ ์„ค์น˜

    $ kubectl apply -f https://raw.githubusercontent.com/cloudtype/agent/master/k8s/v1.0.0/agent.yaml
  2. EKS ํด๋Ÿฌ์Šคํ„ฐ ์—์ด์ „ํŠธ ์ ‘์† ์ฃผ์†Œ ํ™•์ธ

    $ kubectl get svc \
          -n cloudtype \
          agent \
          -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' \
      | xargs -I{} echo "https://{}"
  3. ์—์ด์ „ํŠธ ํ† ํฐ ๊ฐ’ ์กฐํšŒ

    $ kubectl get secrets agent-secret -n cloudtype -o jsonpath='{.data.agent-token}' | base64 --decode
  4. ํด๋ผ์šฐ๋“œํƒ€์ž…์—์„œ ํด๋Ÿฌ์Šคํ„ฐ ์—ฐ๊ฒฐ

    Cloudtype

์ปจํ…Œ์ด๋„ˆ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์—ฐ๊ฒฐ

  1. ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์ •๋ณด ํ™•์ธ

    • AWS ECR ์ฝ˜์†”์—์„œ Create repository ๋ฒ„ํŠผ ๋ˆ„๋ฅธ ํ›„ Repository name ํ•ญ๋ชฉ์—์„œ ECR ์„œ๋ฒ„ ์ฃผ์†Œ ํ™•์ธ

    Cloudtype

  2. ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์„ค์ •์ฐฝ ์ง„์ž…

    • ์ขŒ์ธก ๋„ค๋น„๋ฐ”์—์„œ ํด๋Ÿฌ์Šคํ„ฐ ์„ ํƒ ํ›„ ์„ค์ • ํƒญ์œผ๋กœ ์ด๋™ํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ ์ €์žฅ์†Œ ์—ฐ๊ฒฐํ•˜๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ

    Cloudtype

  3. ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์ •๋ณด ์„ค์ •

    • ์ €์žฅ์†Œ ์ œ๊ณต์ž: AWS Elastic Container Registry
    • ์ ‘์† ์ฃผ์†Œ: 1๋ฒˆ ๊ณผ์ •์—์„œ ํ™•์ธํ•œ ECR ์ ‘์† ์ฃผ์†Œ
    • AWS Access Key Id: ECR ๊ด€๋ จ ๊ถŒํ•œ์ด ๋ถ€์—ฌ๋œ ์‚ฌ์šฉ์ž์˜ Access Key
    • AWS Secret Access Key: ์ƒ๋™
    • Region: ECR ์šด์šฉ ๋Œ€์ƒ ๋ฆฌ์ „

    Cloudtype

ํด๋Ÿฌ์Šคํ„ฐ ๋„คํŠธ์›Œํฌ ์„ค์ •

  1. ์ธ์ฆ์„œ ์‹œํฌ๋ฆฟ ์ด๋ฆ„
    • cloudtype-tls
  2. ์ธ์ฆ์„œ ์‹œํฌ๋ฆฟ ๋„ค์ž„์ŠคํŽ˜์ด์Šค
    • cloudtype
  3. ์ธ์ฆ์„œ ๋ฐœ๊ธ‰๊ธฐ
    • cloudtype-crt
  4. ๊ธฐ๋ณธ ๋„๋ฉ”์ธ
    • ์ด์ „ ๋‹จ๊ณ„์—์„œ Nginx Ingress Controller ์„ธํŒ… ์‹œ ์‚ฌ์šฉํ–ˆ๋˜ Cloudflare ๋„๋ฉ”์ธ
  5. ์ธ๊ทธ๋ ˆ์Šค ์ •๋ณด
    • ์ธ๊ทธ๋ ˆ์Šค ํด๋ž˜์Šค: nginx
    • ์ธ๊ทธ๋ ˆ์Šค IP: Nginx Ingress Controller LoadBalancer ์™ธ๋ถ€ IP/Hostname
  6. ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ์œ ํ˜•
    • LoadBalancer

Cloudtype

ํด๋Ÿฌ์Šคํ„ฐ ์Šคํ† ๋ฆฌ์ง€ ์„ค์ •

  1. ์Šคํ† ๋ฆฌ์ง€ ํด๋ž˜์Šค
    • gp3
    • ์ž…๋ ฅํ•˜์ง€ ์•Š์œผ๋ฉด ํด๋Ÿฌ์Šคํ„ฐ์˜ default ์Šคํ† ๋ฆฌ์ง€ ํด๋ž˜์Šค ์‚ฌ์šฉ
  2. ๋ณผ๋ฅจ ๋ชจ๋“œ
    • RWO

Cloudtype

๐Ÿ“– References

๐Ÿ’ฌ Contact

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors