O eci-profile permite configurar instâncias de contêiner elásticas em um cluster e orquestrar pods com base em seletores. Este tópico descreve como implantar e usar o componente eci-profile.
Recursos do eci-profile
Use o eci-profile para filtrar pods por meio de rótulos de pods e namespaces e implementar os seguintes recursos:
Adicionar anotações e rótulos.
-
Executar políticas de agendamento.
O eci-profile executa as seguintes políticas de agendamento:
Política
Descrição
fair
Define o agendamento equilibrado. O kube-scheduler decide se agenda o pod em um nó real ou em um VNode.
normalNodePrefer
Prioriza o agendamento de pods em nós reais. Se não houver nós reais suficientes, os pods serão agendados em VNodes.
virtualNodeOnly
Restringe o agendamento dos pods exclusivamente aos VNodes.
Neste tópico, o eci-profile usa definições de recursos personalizados (CRDs) de seletor para agendar pods automaticamente. Se você implantou a versão legada do eci-profile, que usa um ConfigMap para agendamento, pode continuar a usá-la. No entanto, recomendamos atualize o eci-profile do modo ConfigMap para o modo CRD de seletor. O modo ConfigMap não oferecerá suporte a novos recursos lançados futuramente. Para mais informações, consulte a seção Atualizar o eci-profile deste tópico.
Implantar o eci-profile
Usar o VNodectl para implantar o eci-profile
Se você já instalou e configure a ferramenta VNodectl, execute os comandos abaixo para implantar o eci-profile de forma simplificada.
-
Implante o eci-profile.
vnode addon enable eci-profile --kubeconfig /path/to/kubeconfig -
Verifique o status da implantação do eci-profile.
vnode addon listO comando retorna uma saída semelhante ao exemplo abaixo. O status do eci-profile deve aparecer como 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 | |----------------|------------|------------|-------------------------------------------------|
Implantar o eci-profile manualmente
-
Crie um arquivo YAML chamado eci-profile.yaml.
Copie o conteúdo abaixo para o arquivo YAML, conforme a versão do seu cluster.
V1.16 and later
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 defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: 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: A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. properties: matchExpressions: description: matchExpressions is a list of label selector requirements. The requirements are ANDed. items: description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. properties: key: description: key is the label key that the selector applies to. type: string operator: description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. type: string values: description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. items: type: string type: array required: - key - operator type: object type: array matchLabels: additionalProperties: type: string description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. type: object type: object x-kubernetes-map-type: atomic objectLabels: description: A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. properties: matchExpressions: description: matchExpressions is a list of label selector requirements. The requirements are ANDed. items: description: A label selector requirement is a selector that contains values, a key, and an operator that relates the key and values. properties: key: description: key is the label key that the selector applies to. type: string operator: description: operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. type: string values: description: values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. items: type: string type: array required: - key - operator type: object type: array matchLabels: additionalProperties: type: string description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are 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 is a set of (resource name, quantity) pairs. 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:443Earlier than 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:443 -
Implante o eci-profile.
kubectl create -f eci-profile.yaml -
Verifique o resultado da implantação.
kubectl -n kube-system get podsO comando retorna uma saída semelhante ao exemplo abaixo. O pod correspondente ao eci-profile deve estar no estado Running.
NAME READY STATUS RESTARTS AGE eci-profile-6454756cb8-8xlz8 1/1 Running 0 76s
Descrição da configuração e exemplos
Após implantar o eci-profile, crie seletores para definir a política de agendamento de pods, bem como as anotações e rótulos desejados. Exemplo de arquivo YAML de um seletor:
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: 3
A tabela a seguir detalha os parâmetros da seção spec:
Parâmetro | Descrição |
objectLabels.matchLabels | Rótulos do pod a serem correspondidos. |
namespaceLabels.matchLabels | Rótulos do namespace a serem correspondidos. |
effect.annotations | Anotações a serem adicionadas. |
effect.labels | Rótulos a serem adicionados. |
policy | Política de agendamento. Valores válidos:
|
priority | Prioridade dos seletores. Em caso de conflito entre múltiplos seletores, aquele com maior prioridade prevalece. Quanto maior o valor, maior a prioridade do seletor. |
Especifique pelo menos um dos parâmetros: objectLabels ou namespaceLabels. Se ambos forem definidos, o pod deverá corresponder aos dois critérios simultaneamente.
Exemplo 1: defina a política de agendamento como fair
Crie o seletor abaixo. Com essa configuração, o eci-profile adiciona tolerâncias de VNode aos pods que possuem o rótulo app: nginx. O kube-scheduler decide se agenda esses pods em nós reais ou VNodes. Além disso, o eci-profile aplica as anotações e rótulos definidos na seção effect aos pods.
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: {}
Exemplo 2: defina a política de agendamento como normalNodePrefer
Crie o seletor a seguir. Por meio dele, o eci-profile agenda os pods com o rótulo app: nginx em VNodes quando os nós reais estiverem insuficientes. As anotações e rótulos especificados na seção effect também são adicionados aos pods.
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: {}
Exemplo 3: defina a política de agendamento como virtualNodeOnly
Crie o seletor abaixo. Ao usá-lo, o eci-profile insere tolerâncias de VNode e nodeSelectors de VNode nos pods rotulados com app: nginx. Adicionalmente, as anotações e rótulos da seção effect são aplicados aos pods.
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: {}
Exemplo 4: agendamento com namespaceResourceLimit
Crie o seletor a seguir. Quando os recursos no namespace especificado ultrapassarem o limite definido, o eci-profile adicionará uma tolerância de VNode aos pods com o rótulo app: nginx, além de aplicar as anotações e rótulos configurados na seção effect.
apiVersion: eci.aliyun.com/v1beta1
kind: Selector
metadata:
name: test-namespace-resource-limit
spec:
objectLabels:
matchLabels:
app: nginx
effect:
annotations:
k8s.aliyun.com/eci-auto-imc: "true"
labels:
eci-schedulable: "true"
policy:
namespaceResourceLimit:
limits:
cpu: 5
memory: 10Gi
Atualizar o eci-profile
Se você usa a versão legada do eci-profile baseada em ConfigMap para agendamento de pods, recomendamos migrar para a versão que usa CRD de seletor. Para atualize o eci-profile, siga estes passos:
Registre o conteúdo dos seletores existentes no namespace kube-system da versão legada do eci-profile.
Exclua a versão legada do eci-profile.
Implante a nova versão do eci-profile.
Recrie os seletores na nova versão com base nas configurações originais registradas.
Em caso de dúvidas durante o uso do eci-profile, participe do grupo do DingTalk (ID: 44666389) para obter suporte técnico.