Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Dukungan EKS Fargate
AWS Fargate
Amazon EKS sekarang dapat meluncurkan pod ke AWS Fargate. Ini menghilangkan kebutuhan untuk khawatir tentang bagaimana Anda menyediakan atau mengelola infrastruktur untuk pod dan membuatnya lebih mudah untuk membangun dan menjalankan aplikasi Kubernetes yang berkinerja tinggi dan sangat tersedia di AWS.
Membuat cluster dengan dukungan Fargate
Anda dapat menambahkan cluster dengan dukungan Fargate dengan:
eksctl create cluster --fargate [ℹ] eksctl version 0.11.0 [ℹ] using region ap-northeast-1 [ℹ] setting availability zones to [ap-northeast-1a ap-northeast-1d ap-northeast-1c] [ℹ] subnets for ap-northeast-1a - public:192.168.0.0/19 private:192.168.96.0/19 [ℹ] subnets for ap-northeast-1d - public:192.168.32.0/19 private:192.168.128.0/19 [ℹ] subnets for ap-northeast-1c - public:192.168.64.0/19 private:192.168.160.0/19 [ℹ] nodegroup "ng-dba9d731" will use "ami-02e124a380df41614" [AmazonLinux2/1.14] [ℹ] using Kubernetes version 1.14 [ℹ] creating EKS cluster "ridiculous-painting-1574859263" in "ap-northeast-1" region [ℹ] will create 2 separate CloudFormation stacks for cluster itself and the initial nodegroup [ℹ] if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=ap-northeast-1 --cluster=ridiculous-painting-1574859263' [ℹ] CloudWatch logging will not be enabled for cluster "ridiculous-painting-1574859263" in "ap-northeast-1" [ℹ] you can enable it with 'eksctl utils update-cluster-logging --enable-types={SPECIFY-YOUR-LOG-TYPES-HERE (e.g. all)} --region=ap-northeast-1 --cluster=ridiculous-painting-1574859263' [ℹ] Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "ridiculous-painting-1574859263" in "ap-northeast-1" [ℹ] 2 sequential tasks: { create cluster control plane "ridiculous-painting-1574859263", create nodegroup "ng-dba9d731" } [ℹ] building cluster stack "eksctl-ridiculous-painting-1574859263-cluster" [ℹ] deploying stack "eksctl-ridiculous-painting-1574859263-cluster" [ℹ] building nodegroup stack "eksctl-ridiculous-painting-1574859263-nodegroup-ng-dba9d731" [ℹ] --nodes-min=2 was set automatically for nodegroup ng-dba9d731 [ℹ] --nodes-max=2 was set automatically for nodegroup ng-dba9d731 [ℹ] deploying stack "eksctl-ridiculous-painting-1574859263-nodegroup-ng-dba9d731" [✔] all EKS cluster resources for "ridiculous-painting-1574859263" have been created [✔] saved kubeconfig as "/Users/marc/.kube/config" [ℹ] adding identity "arn:aws:iam::123456789012:role/eksctl-ridiculous-painting-157485-NodeInstanceRole-104DXUJOFDPO5" to auth ConfigMap [ℹ] nodegroup "ng-dba9d731" has 0 node(s) [ℹ] waiting for at least 2 node(s) to become ready in "ng-dba9d731" [ℹ] nodegroup "ng-dba9d731" has 2 node(s) [ℹ] node "ip-192-168-27-156.ap-northeast-1.compute.internal" is ready [ℹ] node "ip-192-168-95-177.ap-northeast-1.compute.internal" is ready [ℹ] creating Fargate profile "default" on EKS cluster "ridiculous-painting-1574859263" [ℹ] created Fargate profile "default" on EKS cluster "ridiculous-painting-1574859263" [ℹ] kubectl command should work with "/Users/marc/.kube/config", try 'kubectl get nodes' [✔] EKS cluster "ridiculous-painting-1574859263" in "ap-northeast-1" region is ready
Perintah ini akan membuat cluster dan profil Fargate. Profil ini berisi informasi tertentu yang diperlukan oleh AWS untuk membuat instance pod di Fargate. Ini adalah:
-
peran eksekusi pod untuk menentukan izin yang diperlukan untuk menjalankan pod dan lokasi jaringan (subnet) untuk menjalankan pod. Hal ini memungkinkan izin jaringan dan keamanan yang sama diterapkan ke beberapa Pod Fargate dan membuatnya lebih mudah untuk memigrasi pod yang ada di klaster ke Fargate.
-
Selector untuk menentukan pod mana yang harus dijalankan di Fargate. Ini disusun oleh a
namespace
danlabels
.
Ketika profil tidak ditentukan tetapi dukungan untuk Fargate diaktifkan dengan --fargate
profil Fargate default dibuat. Profil ini menargetkan default
dan kube-system
namespace sehingga pod di namespace tersebut akan berjalan di Fargate.
Profil Fargate yang dibuat dapat diperiksa dengan perintah berikut:
eksctl get fargateprofile --cluster ridiculous-painting-1574859263 -o yaml - name: fp-default podExecutionRoleARN: arn:aws:iam::123456789012:role/eksctl-ridiculous-painting-1574859263-ServiceRole-EIFQOH0S1GE7 selectors: - namespace: default - namespace: kube-system subnets: - subnet-0b3a5522f3b48a742 - subnet-0c35f1497067363f3 - subnet-0a29aa00b25082021
Untuk mempelajari selengkapnya tentang penyeleksi, lihat Merancang profil Fargate.
Membuat cluster dengan dukungan Fargate menggunakan file konfigurasi
File konfigurasi berikut mendeklarasikan cluster EKS dengan nodegroup yang terdiri dari satu instance EC2 m5.large
dan dua profil Fargate. Semua pod yang didefinisikan dalam default
dan kube-system
namespace akan berjalan di Fargate. Semua pod di dev
namespace yang juga memiliki label juga dev=passed
akan berjalan di Fargate. Pod lain akan dijadwalkan pada node ding-1
.
# An example of ClusterConfig with a normal nodegroup and a Fargate profile. --- apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: fargate-cluster region: ap-northeast-1 nodeGroups: - name: ng-1 instanceType: m5.large desiredCapacity: 1 fargateProfiles: - name: fp-default selectors: # All workloads in the "default" Kubernetes namespace will be # scheduled onto Fargate: - namespace: default # All workloads in the "kube-system" Kubernetes namespace will be # scheduled onto Fargate: - namespace: kube-system - name: fp-dev selectors: # All workloads in the "dev" Kubernetes namespace matching the following # label selectors will be scheduled onto Fargate: - namespace: dev labels: env: dev checks: passed
eksctl create cluster -f cluster-fargate.yaml [ℹ] eksctl version 0.11.0 [ℹ] using region ap-northeast-1 [ℹ] setting availability zones to [ap-northeast-1c ap-northeast-1a ap-northeast-1d] [ℹ] subnets for ap-northeast-1c - public:192.168.0.0/19 private:192.168.96.0/19 [ℹ] subnets for ap-northeast-1a - public:192.168.32.0/19 private:192.168.128.0/19 [ℹ] subnets for ap-northeast-1d - public:192.168.64.0/19 private:192.168.160.0/19 [ℹ] nodegroup "ng-1" will use "ami-02e124a380df41614" [AmazonLinux2/1.14] [ℹ] using Kubernetes version 1.14 [ℹ] creating EKS cluster "fargate-cluster" in "ap-northeast-1" region with Fargate profile and un-managed nodes [ℹ] 1 nodegroup (ng-1) was included (based on the include/exclude rules) [ℹ] will create a CloudFormation stack for cluster itself and 1 nodegroup stack(s) [ℹ] will create a CloudFormation stack for cluster itself and 0 managed nodegroup stack(s) [ℹ] if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=ap-northeast-1 --cluster=fargate-cluster' [ℹ] CloudWatch logging will not be enabled for cluster "fargate-cluster" in "ap-northeast-1" [ℹ] you can enable it with 'eksctl utils update-cluster-logging --enable-types={SPECIFY-YOUR-LOG-TYPES-HERE (e.g. all)} --region=ap-northeast-1 --cluster=fargate-cluster' [ℹ] Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "fargate-cluster" in "ap-northeast-1" [ℹ] 2 sequential tasks: { create cluster control plane "fargate-cluster", create nodegroup "ng-1" } [ℹ] building cluster stack "eksctl-fargate-cluster-cluster" [ℹ] deploying stack "eksctl-fargate-cluster-cluster" [ℹ] building nodegroup stack "eksctl-fargate-cluster-nodegroup-ng-1" [ℹ] --nodes-min=1 was set automatically for nodegroup ng-1 [ℹ] --nodes-max=1 was set automatically for nodegroup ng-1 [ℹ] deploying stack "eksctl-fargate-cluster-nodegroup-ng-1" [✔] all EKS cluster resources for "fargate-cluster" have been created [✔] saved kubeconfig as "/home/user1/.kube/config" [ℹ] adding identity "arn:aws:iam::123456789012:role/eksctl-fargate-cluster-nod-NodeInstanceRole-42Q80B2Z147I" to auth ConfigMap [ℹ] nodegroup "ng-1" has 0 node(s) [ℹ] waiting for at least 1 node(s) to become ready in "ng-1" [ℹ] nodegroup "ng-1" has 1 node(s) [ℹ] node "ip-192-168-71-83.ap-northeast-1.compute.internal" is ready [ℹ] creating Fargate profile "fp-default" on EKS cluster "fargate-cluster" [ℹ] created Fargate profile "fp-default" on EKS cluster "fargate-cluster" [ℹ] creating Fargate profile "fp-dev" on EKS cluster "fargate-cluster" [ℹ] created Fargate profile "fp-dev" on EKS cluster "fargate-cluster" [ℹ] "coredns" is now schedulable onto Fargate [ℹ] "coredns" is now scheduled onto Fargate [ℹ] "coredns" is now scheduled onto Fargate [ℹ] "coredns" pods are now scheduled onto Fargate [ℹ] kubectl command should work with "/home/user1/.kube/config", try 'kubectl get nodes' [✔] EKS cluster "fargate-cluster" in "ap-northeast-1" region is ready
Merancang profil Fargate
Setiap entri pemilih memiliki hingga dua komponen, namespace dan daftar pasangan kunci-nilai. Hanya komponen namespace yang diperlukan untuk membuat entri pemilih. Semua aturan (namespace, pasangan nilai kunci) harus diterapkan ke pod agar sesuai dengan entri pemilih. Sebuah pod hanya perlu mencocokkan satu entri pemilih untuk dijalankan di profil. Pod apa pun yang cocok dengan semua kondisi di bidang pemilih akan dijadwalkan untuk dijalankan di Fargate. Pod apa pun yang tidak cocok dengan Namespace yang masuk daftar putih tetapi di mana pengguna secara manual menyetel scheduler: fargate-scheduler filed akan macet dalam status Pending, karena mereka tidak diizinkan untuk dijalankan di Fargate.
Profil harus memenuhi persyaratan berikut:
-
Satu pemilih wajib per profil
-
Setiap pemilih harus menyertakan namespace; label bersifat opsional
Contoh: penjadwalan beban kerja di Fargate
Untuk menjadwalkan pod di Fargate untuk contoh yang disebutkan di atas, seseorang dapat, misalnya, membuat namespace yang dipanggil dev
dan menerapkan beban kerja di sana:
kubectl create namespace dev namespace/dev created kubectl run nginx --image=nginx --restart=Never --namespace dev pod/nginx created kubectl get pods --all-namespaces --output wide NAMESPACE NAME READY STATUS AGE IP NODE dev nginx 1/1 Running 75s 192.168.183.140 fargate-ip-192-168-183-140.ap-northeast-1.compute.internal kube-system aws-node-44qst 1/1 Running 21m 192.168.70.246 ip-192-168-70-246.ap-northeast-1.compute.internal kube-system aws-node-4vr66 1/1 Running 21m 192.168.23.122 ip-192-168-23-122.ap-northeast-1.compute.internal kube-system coredns-699bb99bf8-84x74 1/1 Running 26m 192.168.2.95 ip-192-168-23-122.ap-northeast-1.compute.internal kube-system coredns-699bb99bf8-f6x6n 1/1 Running 26m 192.168.90.73 ip-192-168-70-246.ap-northeast-1.compute.internal kube-system kube-proxy-brxhg 1/1 Running 21m 192.168.23.122 ip-192-168-23-122.ap-northeast-1.compute.internal kube-system kube-proxy-zd7s8 1/1 Running 21m 192.168.70.246 ip-192-168-70-246.ap-northeast-1.compute.internal
Dari output dari kubectl get pods
perintah terakhir kita dapat melihat bahwa nginx
pod dideploy dalam sebuah node yang disebutfargate-ip-192-168-183-140.ap-northeast-1.compute.internal
.
Mengelola profil Fargate
Untuk menerapkan beban kerja Kubernetes di Fargate, EKS membutuhkan profil Fargate. Saat membuat cluster seperti pada contoh di ataseksctl
, atasi ini dengan membuat profil default. Mengingat cluster yang sudah ada, dimungkinkan juga untuk membuat profil Fargate dengan perintah: eksctl create fargateprofile
catatan
Operasi ini hanya didukung pada cluster yang berjalan pada versi platform EKS eks.5
atau lebih tinggi.
catatan
Jika yang sudah ada dibuat dengan versi eksctl
sebelum 0.11.0, Anda harus menjalankan eksctl upgrade
cluster
sebelum membuat profil Fargate.
eksctl create fargateprofile --namespace dev --cluster fargate-example-cluster [ℹ] creating Fargate profile "fp-9bfc77ad" on EKS cluster "fargate-example-cluster" [ℹ] created Fargate profile "fp-9bfc77ad" on EKS cluster "fargate-example-cluster"
Anda juga dapat menentukan nama profil Fargate yang akan dibuat. Nama ini tidak boleh dimulai dengan awalaneks-
.
eksctl create fargateprofile --namespace dev --cluster fargate-example-cluster --name fp-development [ℹ] created Fargate profile "fp-development" on EKS cluster "fargate-example-cluster"
Menggunakan perintah ini dengan bendera CLI eksctl hanya dapat membuat profil Fargate tunggal dengan pemilih sederhana. Untuk pemilih yang lebih kompleks, misalnya dengan lebih banyak ruang nama, eksctl mendukung penggunaan file konfigurasi:
apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: fargate-example-cluster region: ap-northeast-1 fargateProfiles: - name: fp-default selectors: # All workloads in the "default" Kubernetes namespace will be # scheduled onto Fargate: - namespace: default # All workloads in the "kube-system" Kubernetes namespace will be # scheduled onto Fargate: - namespace: kube-system - name: fp-dev selectors: # All workloads in the "dev" Kubernetes namespace matching the following # label selectors will be scheduled onto Fargate: - namespace: dev labels: env: dev checks: passed
eksctl create fargateprofile -f fargate-example-cluster.yaml [ℹ] creating Fargate profile "fp-default" on EKS cluster "fargate-example-cluster" [ℹ] created Fargate profile "fp-default" on EKS cluster "fargate-example-cluster" [ℹ] creating Fargate profile "fp-dev" on EKS cluster "fargate-example-cluster" [ℹ] created Fargate profile "fp-dev" on EKS cluster "fargate-example-cluster" [ℹ] "coredns" is now scheduled onto Fargate [ℹ] "coredns" pods are now scheduled onto Fargate
Untuk melihat profil Fargate yang ada dalam sebuah cluster:
eksctl get fargateprofile --cluster fargate-example-cluster NAME SELECTOR_NAMESPACE SELECTOR_LABELS POD_EXECUTION_ROLE_ARN SUBNETS fp-9bfc77ad dev <none> arn:aws:iam::123456789012:role/eksctl-fargate-example-cluster-ServiceRole-1T5F78E5FSH79 subnet-00adf1d8c99f83381,subnet-04affb163ffab17d4,subnet-035b34379d5ef5473
Dan untuk melihatnya dalam yaml
format:
eksctl get fargateprofile --cluster fargate-example-cluster -o yaml - name: fp-9bfc77ad podExecutionRoleARN: arn:aws:iam::123456789012:role/eksctl-fargate-example-cluster-ServiceRole-1T5F78E5FSH79 selectors: - namespace: dev subnets: - subnet-00adf1d8c99f83381 - subnet-04affb163ffab17d4 - subnet-035b34379d5ef5473
Atau dalam json
format:
eksctl get fargateprofile --cluster fargate-example-cluster -o json [ { "name": "fp-9bfc77ad", "podExecutionRoleARN": "arn:aws:iam::123456789012:role/eksctl-fargate-example-cluster-ServiceRole-1T5F78E5FSH79", "selectors": [ { "namespace": "dev" } ], "subnets": [ "subnet-00adf1d8c99f83381", "subnet-04affb163ffab17d4", "subnet-035b34379d5ef5473" ] } ]
Profil Fargate tidak dapat diubah menurut desain. Untuk mengubah sesuatu, buat profil Fargate baru dengan perubahan yang diinginkan dan hapus yang lama dengan eksctl delete fargateprofile
perintah seperti pada contoh berikut:
eksctl delete fargateprofile --cluster fargate-example-cluster --name fp-9bfc77ad --wait 2019-11-27T19:04:26+09:00 [ℹ] deleting Fargate profile "fp-9bfc77ad" ClusterName: "fargate-example-cluster", FargateProfileName: "fp-9bfc77ad" }
Perhatikan bahwa penghapusan profil adalah proses yang dapat memakan waktu hingga beberapa menit. Ketika --wait
flag tidak ditentukan, eksctl
secara optimis mengharapkan profil dihapus dan kembali segera setelah permintaan AWS API dikirim. Untuk membuat eksctl
menunggu sampai profil telah berhasil dihapus, gunakan --wait
seperti pada contoh di atas.