eci-profile memungkinkan Anda mengonfigurasi instance kontainer elastis dalam kluster dan mengatur pod berdasarkan pemilih. Topik ini menjelaskan cara menerapkan dan menggunakan komponen eci-profile.
Fitur eci-profile
Anda dapat menggunakan eci-profile untuk memfilter pod dengan label pod dan namespace serta menerapkan fitur berikut:
Menambahkan anotasi dan label.
Menjalankan kebijakan penjadwalan.
eci-profile mendukung kebijakan penjadwalan berikut:
Kebijakan
Deskripsi
fair
Kebijakan ini menentukan penjadwalan yang adil. kube-scheduler menentukan untuk menjadwalkan pod ke node nyata atau VNode.
normalNodePrefer
Pod diutamakan dijadwalkan ke node nyata. Jika node nyata tidak mencukupi, pod dapat dijadwalkan ke VNode.
virtualNodeOnly
Pod hanya dijadwalkan ke VNode.
Dalam topik ini, eci-profile menggunakan definisi sumber daya kustom (CRD) pemilih untuk secara otomatis menjadwalkan pod. Jika Anda telah menerapkan eci-profile lama yang menggunakan ConfigMap untuk menjadwalkan pod, Anda dapat terus menggunakannya. Namun, kami merekomendasikan agar Anda memperbarui eci-profile dari mode ConfigMap ke mode CRD pemilih. Mode ConfigMap tidak lagi mendukung fitur baru yang akan dirilis di masa mendatang. Untuk informasi lebih lanjut, lihat bagian Perbarui eci-profile dari topik ini.
Terapkan eci-profile
Gunakan VNodectl untuk menerapkan eci-profile
Jika Anda telah menginstal dan mengonfigurasi alat VNodectl, Anda dapat menjalankan perintah berikut untuk menerapkan eci-profile dengan mudah.
Terapkan eci-profile.
vnode addon enable eci-profile --kubeconfig /path/to/kubeconfigLihat status penerapan eci-profile.
vnode addon listKeluaran perintah berikut menunjukkan bahwa status eci-profile adalah enabled.
|----------------|------------|------------|-------------------------------------------------| | ADDON NAME | STATUS | MAINTAINER | REPOSITORY | |----------------|------------|------------|-------------------------------------------------| | eci-profile | enabled ✅ | ECI Group | https://github.com/aliyuneci/eci-profile.git | | vnode-approver | enabled ✅ | ECI Group | https://github.com/aliyuneci/vnode-approver.git | |----------------|------------|------------|-------------------------------------------------|
Secara manual terapkan eci-profile
Buat file YAML bernama eci-profile.yaml.
Salin konten berikut ke file YAML sesuai versi kluster Anda.
V1.16 dan yang lebih baru
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: eci-profile rules: - apiGroups: - "" resources: - nodes - namespaces - resourcequotas verbs: - get - list - watch - apiGroups: - "" resources: - pods verbs: - get - list - watch - create - patch - apiGroups: - "admissionregistration.k8s.io" resources: - mutatingwebhookconfigurations verbs: - get - patch - create - delete - apiGroups: - "eci.aliyun.com" resources: - selectors verbs: - get - watch - list --- apiVersion: v1 kind: ServiceAccount metadata: name: eci-profile namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: eci-profile roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: eci-profile subjects: - kind: ServiceAccount name: eci-profile namespace: kube-system --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) creationTimestamp: null name: selectors.eci.aliyun.com spec: group: eci.aliyun.com names: kind: Selector listKind: SelectorList plural: selectors singular: selector scope: Namespaced versions: - name: v1 schema: openAPIV3Schema: properties: apiVersion: description: 'APIVersion mendefinisikan skema versi dari representasi ini dari sebuah objek. Server harus mengonversi skema yang dikenali ke nilai internal terbaru, dan dapat menolak nilai yang tidak dikenali. Informasi lebih lanjut: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: description: 'Kind adalah nilai string yang mewakili sumber daya REST yang objek ini wakili. Server dapat menyimpulkan ini dari endpoint tempat klien mengirimkan permintaan. Tidak dapat diperbarui. Dalam CamelCase. Informasi lebih lanjut: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object spec: properties: effect: properties: annotations: additionalProperties: type: string type: object labels: additionalProperties: type: string type: object type: object namespaceLabels: description: Pemilih label adalah kueri label atas satu set sumber daya. Hasil dari matchLabels dan matchExpressions adalah ANDed. Pemilih label kosong cocok dengan semua objek. Pemilih label nol cocok dengan tidak ada objek. properties: matchExpressions: description: matchExpressions adalah daftar persyaratan pemilih label. Persyaratannya adalah ANDed. items: description: Persyaratan pemilih label adalah pemilih yang berisi nilai, kunci, dan operator yang menghubungkan kunci dan nilai. properties: key: description: key adalah kunci label yang pemilih tersebut berlaku untuk. type: string operator: description: operator mewakili hubungan kunci dengan satu set nilai. Operator yang valid adalah In, NotIn, Exists dan DoesNotExist. type: string values: description: values adalah array nilai string. Jika operator adalah In atau NotIn, array values harus tidak kosong. Jika operator adalah Exists atau DoesNotExist, array values harus kosong. Array ini diganti selama strategic merge patch. items: type: string type: array required: - key - operator type: object type: array matchLabels: additionalProperties: type: string description: matchLabels adalah peta pasangan {key,value}. Sebuah {key,value} tunggal dalam peta matchLabels setara dengan elemen dari matchExpressions, yang bidang kuncinya adalah "key", operatornya adalah "In", dan array values hanya berisi "value". Persyaratannya adalah ANDed. type: object type: object x-kubernetes-map-type: atomic objectLabels: description: Pemilih label adalah kueri label atas satu set sumber daya. Hasil dari matchLabels dan matchExpressions adalah ANDed. Pemilih label kosong cocok dengan semua objek. Pemilih label nol cocok dengan tidak ada objek. properties: matchExpressions: description: matchExpressions adalah daftar persyaratan pemilih label. Persyaratannya adalah ANDed. items: description: Persyaratan pemilih label adalah pemilih yang berisi nilai, kunci, dan operator yang menghubungkan kunci dan nilai. properties: key: description: key adalah kunci label yang pemilih tersebut berlaku untuk. type: string operator: description: operator mewakili hubungan kunci dengan satu set nilai. Operator yang valid adalah In, NotIn, Exists dan DoesNotExist. type: string values: description: values adalah array nilai string. Jika operator adalah In atau NotIn, array values harus tidak kosong. Jika operator adalah Exists atau DoesNotExist, array values harus kosong. Array ini diganti selama strategic merge patch. items: type: string type: array required: - key - operator type: object type: array matchLabels: additionalProperties: type: string description: matchLabels adalah peta pasangan {key,value}. Sebuah {key,value} tunggal dalam peta matchLabels setara dengan elemen dari matchExpressions, yang bidang kuncinya adalah "key", operatornya adalah "In", dan array values hanya berisi "value". Persyaratannya adalah ANDed. type: object type: object x-kubernetes-map-type: atomic policy: properties: fair: type: object namespaceResourceLimit: properties: limits: additionalProperties: anyOf: - type: integer - type: string pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true description: ResourceList adalah satu set pasangan (nama sumber daya, jumlah). type: object namespace: type: string required: - limits - namespace type: object normalNodeOnly: type: object normalNodePrefer: properties: cpuRatio: type: integer memoryRatio: type: integer type: object virtualNodeOnly: type: object type: object priority: format: int32 type: integer type: object required: - spec type: object served: true storage: true --- apiVersion: v1 kind: Service metadata: labels: role: eci-profile name: eci-profile namespace: kube-system spec: ports: - port: 443 targetPort: 443 selector: app: eci-profile --- apiVersion: apps/v1 kind: Deployment metadata: name: eci-profile namespace: kube-system labels: app: eci-profile spec: replicas: 1 selector: matchLabels: app: eci-profile template: metadata: labels: app: eci-profile spec: serviceAccount: eci-profile containers: - name: eci-profile image: registry.cn-beijing.aliyuncs.com/eci-release/eci-profile:0.0.3 imagePullPolicy: Always resources: requests: cpu: 2 memory: 4Gi limits: cpu: 4 memory: 8Gi env: - name: KUBERNETES_MASTER value: https://kubernetes:443Sebelum V1.16
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: eci-profile rules: - apiGroups: - "" resources: - nodes - namespaces - resourcequotas verbs: - get - list - watch - apiGroups: - "" resources: - pods verbs: - get - list - watch - create - patch - apiGroups: - "admissionregistration.k8s.io" resources: - mutatingwebhookconfigurations verbs: - get - patch - create - delete - apiGroups: - "eci.aliyun.com" resources: - selectors verbs: - get - watch - list --- apiVersion: apiextensions.k8s.io/v1beta1 #apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: selectors.eci.aliyun.com spec: group: eci.aliyun.com version: v1beta1 names: kind: Selector plural: selectors shortNames: - selectors categories: - all scope: Cluster validation: openAPIV3Schema: type: object required: - metadata - spec properties: apiVersion: type: string kind: type: string metadata: type: object spec: type: object --- apiVersion: v1 kind: ServiceAccount metadata: name: eci-profile namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: eci-profile roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: eci-profile subjects: - kind: ServiceAccount name: eci-profile namespace: kube-system --- apiVersion: v1 kind: Service metadata: labels: role: eci-profile name: eci-profile namespace: kube-system spec: ports: - port: 443 targetPort: 443 selector: app: eci-profile --- apiVersion: apps/v1 kind: Deployment metadata: name: eci-profile namespace: kube-system labels: app: eci-profile spec: replicas: 1 selector: matchLabels: app: eci-profile template: metadata: labels: app: eci-profile spec: serviceAccount: eci-profile containers: - name: eci-profile image: registry.cn-beijing.aliyuncs.com/eci-release/eci-profile:2.0.0-477875b-aliyun imagePullPolicy: Always resources: requests: cpu: 2 memory: 4Gi limits: cpu: 4 memory: 8Gi env: - name: KUBERNETES_MASTER value: https://kubernetes:443Terapkan eci-profile.
kubectl create -f eci-profile.yamlLihat hasil penerapan.
kubectl -n kube-system get podsKeluaran perintah berikut menunjukkan bahwa pod yang sesuai dengan eci-profile berada dalam status Running.
NAME READY STATUS RESTARTS AGE eci-profile-6454756cb8-8xlz8 1/1 Running 0 76s
Deskripsi konfigurasi dan contoh konfigurasi
Setelah menerapkan eci-profile, Anda dapat membuat pemilih untuk mengonfigurasi kebijakan penjadwalan pod, serta menambahkan anotasi dan label. Contoh file YAML pemilih:
apiVersion: eci.aliyun.com/v1beta1
kind: Selector
metadata:
name: test-fair
spec:
objectLabels:
matchLabels:
app: nginx
namespaceLabels:
matchLabels:
app: test
effect:
annotations:
k8s.aliyun.com/eci-auto-imc: "true"
labels:
eci-schedulable: "true"
policy:
fair: {}
priority: 3Tabel berikut menjelaskan parameter dalam bagian spec:
Parameter | Deskripsi |
objectLabels.matchLabels | Label pod yang cocok. |
namespaceLabels.matchLabels | Label namespace yang cocok. |
effect.annotations | Anotasi yang ingin Anda tambahkan. |
effect.labels | Label yang ingin Anda tambahkan. |
policy | Kebijakan penjadwalan. Nilai yang valid:
|
priority | Prioritas pemilih. Jika Anda mengonfigurasi beberapa pemilih yang bertentangan, pemilih dengan prioritas lebih tinggi akan berlaku. Nilai parameter yang lebih besar menunjukkan prioritas yang lebih tinggi untuk pemilih. |
Anda harus menentukan setidaknya salah satu parameter objectLabels atau namespaceLabels. Jika Anda menentukan kedua parameter tersebut, pod harus cocok dengan keduanya.
Contoh 1: atur kebijakan penjadwalan ke fair
Buat pemilih berikut. Dengan menggunakan pemilih, eci-profile menambahkan toleransi VNode ke pod dengan label app: nginx. kube-scheduler menentukan apakah pod dijadwalkan ke node nyata atau VNode. eci-profile juga menambahkan anotasi dan label yang didefinisikan dalam bagian effect ke pod.
apiVersion: eci.aliyun.com/v1beta1
kind: Selector
metadata:
name: test-fair
spec:
objectLabels:
matchLabels:
app: nginx
effect:
annotations:
k8s.aliyun.com/eci-auto-imc: "true"
labels:
eci-schedulable: "true"
policy:
fair: {}Contoh 2: atur kebijakan penjadwalan ke normalNodePrefer
Buat pemilih berikut. Dengan menggunakan pemilih, eci-profile menjadwalkan pod dengan label app: nginx ke VNode jika node nyata tidak mencukupi. eci-profile juga menambahkan anotasi dan label yang didefinisikan dalam bagian effect ke pod.
apiVersion: eci.aliyun.com/v1beta1
kind: Selector
metadata:
name: test-normal-node-prefer
spec:
objectLabels:
matchLabels:
app: nginx
effect:
annotations:
k8s.aliyun.com/eci-image-cache: "true"
labels:
eci-schedulable: "true"
policy:
normalNodePrefer: {}Contoh 3: atur kebijakan penjadwalan ke virtualNodeOnly
Buat pemilih berikut. Dengan menggunakan pemilih, eci-profile menambahkan toleransi VNode dan nodeSelectors VNode ke pod dengan label app: nginx. eci-profile juga menambahkan anotasi dan label yang didefinisikan dalam bagian effect ke pod.
apiVersion: eci.aliyun.com/v1beta1
kind: Selector
metadata:
name: test-virtual-node-only
spec:
objectLabels:
matchLabels:
app: nginx
effect:
annotations:
k8s.aliyun.com/eci-auto-imc: "true"
labels:
eci-schedulable: "true"
policy:
virtualNodeOnly: {}Perbarui eci-profile
Jika Anda telah menerapkan eci-profile lama yang menggunakan ConfigMap untuk menjadwalkan pod, kami sarankan Anda memperbarui eci-profile ke versi yang menggunakan CRD pemilih untuk menjadwalkan pod. Untuk memperbarui eci-profile, lakukan langkah-langkah berikut:
Catat isi pemilih di namespace kube-system dari eci-profile lama.
Hapus eci-profile lama.
Terapkan eci-profile baru.
Buat pemilih baru berdasarkan pemilih asli.
Jika Anda memiliki pertanyaan saat menggunakan eci-profile, bergabunglah dengan grup DingTalk (ID: 44666389) untuk mendapatkan dukungan teknis.