Thứ Ba, 21 tháng 10, 2025

Bài 5: Kubernetes EKS AWS – Triển Khai Cluster Trên AWS

Danh sách bài viết trong series Kubernetes cơ bản
  • Bài 1: Kubernetes Cơ Bản – Cài Đặt Minikube Và Chạy Pod Đầu Tiên
  • Bài 2: Kubernetes Pod Deployment – Triển Khai Ứng Dụng Đầu Tiên
  • Bài 3: Kubernetes Service Ingress – Quản Lý Truy Cập Ứng Dụng
  • Bài 4: Kubernetes ConfigMap Secret – Quản Lý Cấu Hình Ứng Dụng
  • Bài 5: Kubernetes EKS AWS – Triển Khai Cluster Trên AWS
  • Bài 6: Kubernetes Helm – Tự Động Triển Khai Ứng Dụng Dễ Dàng
  • Bài 7: Kubernetes CI/CD – Tự Động Triển Khai Với GitHub Actions
  • Bài 8: Kubernetes Monitoring – Giám Sát Với Prometheus Và Grafana
  • Bài 9: Kubernetes Autoscaling – Tối Ưu Hóa Cluster Hiệu Quả

EKS Là Gì?

Kubernetes EKS AWS là cách triển khai Kubernetes trên Amazon Elastic Kubernetes Service (EKS), một dịch vụ quản lý Kubernetes của AWS. EKS giúp bạn dễ dàng chạy cluster Kubernetes mà không cần tự quản lý control plane. Trong các bài trước, bạn đã dùng Minikube để thử nghiệm local. Bài này sẽ hướng dẫn bạn triển khai cluster EKS trên AWS và chạy ứng dụng đơn giản (Nginx).

Lưu ý: Bạn cần tài khoản AWS, đã cài AWS CLI, kubectl, và eksctl. Hướng dẫn này dùng eksctl 0.185.0 trên Ubuntu 22.04, vùng us-east-1.

Bước 1: Chuẩn Bị Môi Trường AWS Và Cài Đặt Công Cụ

  • Hành động:
    1. Cấu hình AWS CLI:
      aws configure

      Nhập Access Key, Secret Key, và vùng us-east-1.

    2. Cài đặt eksctl:
      curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
      sudo mv /tmp/eksctl /usr/local/bin
    3. Kiểm tra eksctl:
      eksctl version
  • Kết quả thực tế:
    • Sau khi chạy aws configure, kiểm tra:
      aws sts get-caller-identity

      Output:

      {
      "UserId": "AIDAXYZ1234567890",
      "Account": "123456789012",
      "Arn": "arn:aws:iam::123456789012:user/your-user"
      }
    • Sau khi cài eksctl, lệnh eksctl version hiển thị:
      0.185.0

Bước 2: Tạo Cluster EKS Với eksctl

  • Hành động:
    1. Tạo cluster EKS:
      eksctl create cluster --name my-cluster --region us-east-1 --nodegroup-name my-nodes --node-type t3.small --nodes 2

      (Lệnh này tạo cluster my-cluster với 2 node loại t3.small).

    2. Kiểm tra cluster:
      kubectl get nodes
  • Kết quả thực tế:
    • Sau khi chạy eksctl create cluster (mất khoảng 10-15 phút), terminal hiển thị:
      [ℹ]  eksctl version 0.185.0
      [ℹ]  using region us-east-1
      [✔]  EKS cluster "my-cluster" in "us-east-1" region is ready
    • Lệnh kubectl get nodes hiển thị:
      NAME                          STATUS   ROLES    AGE   VERSION
      ip-192-168-1-100.ec2.internal   Ready    
      <none>   5m    v1.29.0
      ip-192-168-1-101.ec2.internal   Ready    
      <none>   5m    v1.29.0

      (Cluster có 2 node ở trạng thái Ready).

Bước 3: Triển Khai Ứng Dụng Đơn Giản Trên EKS

  • Hành động:
    1. Tạo file nginx-deployment.yaml:
      touch nginx-deployment.yaml

      Mở file và dán nội dung:

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: nginx-deployment
      spec:
      replicas: 2
      selector:
       matchLabels:
         app: nginx
      template:
       metadata:
         labels:
           app: nginx
       spec:
         containers:
         - name: nginx
           image: nginx:latest
           ports:
           - containerPort: 80
      ---
      apiVersion: v1
      kind: Service
      metadata:
      name: nginx-service
      spec:
      selector:
       app: nginx
      ports:
      - protocol: TCP
       port: 80
       targetPort: 80
      type: LoadBalancer
    2. Triển khai ứng dụng:
      kubectl apply -f nginx-deployment.yaml
    3. Kiểm tra Service để lấy URL:
      kubectl get services
    4. Truy cập URL của Service trên trình duyệt.
  • Kết quả thực tế:
    • Sau khi chạy kubectl apply, terminal hiển thị:
      deployment.apps/nginx-deployment created
      service/nginx-service created
    • Lệnh kubectl get services hiển thị:
      NAME            TYPE           CLUSTER-IP      EXTERNAL-IP                                                              PORT(S)        AGE
      kubernetes      ClusterIP      10.100.0.1      
      <none>                                                                   443/TCP        15m
      nginx-service   LoadBalancer   10.100.123.456  a12bc34de56f78g901hi234jklmn.elb.us-east-1.amazonaws.com   80:31234/TCP   30s
    • Truy cập URL http://a12bc34de56f78g901hi234jklmn.elb.us-east-1.amazonaws.com, bạn thấy:
      Welcome to nginx!

Bước 4: Xóa Tài Nguyên Để Dọn Dẹp

  • Hành động:
    1. Xóa Deployment và Service:
      kubectl delete -f nginx-deployment.yaml
    2. Xóa cluster EKS:
      eksctl delete cluster --name my-cluster --region us-east-1
  • Kết quả thực tế:
    • Sau khi chạy kubectl delete, terminal hiển thị:
      deployment.apps "nginx-deployment" deleted
      service "nginx-service" deleted
    • Sau khi chạy eksctl delete cluster (mất khoảng 5-10 phút), terminal hiển thị:
      [✔]  all resources in cluster my-cluster were deleted

Lưu Ý Quan Trọng

  • Chi phí AWS: EKS có phí $0.10/giờ cho control plane (~$72/tháng). Node t3.small khoảng $0.02/giờ. Luôn xóa cluster sau khi thử nghiệm.
  • IAM Role: eksctl tự động tạo IAM role cho cluster. Trong production, bạn nên cấu hình role cụ thể.
  • Tài liệu tham khảo: Xem thêm về EKS (AWS EKS Documentation) và eksctl (eksctl Documentation).
=============================
Website không chứa bất kỳ quảng cáo nào, mọi đóng góp để duy trì phát triển cho website (donation) xin vui lòng gửi về STK 90.2142.8888 - Ngân hàng Vietcombank Thăng Long - TRAN VAN BINH
=============================
Nếu bạn không muốn bị AI thay thế và tiết kiệm 3-5 NĂM trên con đường trở thành DBA chuyên nghiệp hay làm chủ Database thì hãy đăng ký ngay KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE, được Coaching trực tiếp từ tôi với toàn bộ bí kíp thực chiến, thủ tục, quy trình của gần 20 năm kinh nghiệm (mà bạn sẽ KHÔNG THỂ tìm kiếm trên Internet/Google) từ đó giúp bạn dễ dàng quản trị mọi hệ thống Core tại Việt Nam và trên thế giới, đỗ OCP.
- CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
- Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
2 khóa học online qua video giúp bạn nhanh chóng có những kiến thức nền tảng về Linux, Oracle, học mọi nơi, chỉ cần có Internet/4G:
- Oracle cơ bản: https://bit.ly/admin_1200
- Linux: https://bit.ly/linux_1200
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: https://www.youtube.com/@binhguru
👨 Tiktok: https://www.tiktok.com/@binhguru
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhguru
👨 Podcast: https://www.podbean.com/pu/pbblog-eskre-5f82d6
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
cơ sở dữ liệu, cơ sở dữ liệu quốc gia, database, AI, trí tuệ nhân tạo, artificial intelligence, machine learning, deep learning, LLM, ChatGPT, DeepSeek, Grok, oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c/21c/23c/23ai, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, ms sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, docker, k8s, micro service, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master