Alibaba Cloud Cloud Provider

repository·master·Indexed 18 days ago

https://github.com/kubernetes/cloud-provider-alibaba-cloud

An external Kubernetes Cloud Controller Manager (CCM) implementation for Alibaba Cloud. It enables Kubernetes clusters to interact with Alibaba Cloud infrastructure and services, supporting VPC networks and LoadBalancer service integration. The project includes a DryRun mode for non-destructive testing of controller logic and provides guides for installation via kubeadm and RKE.

Tokens
15.6K
Snippets
36
Records
49
Agent score
62%

What's inside cloud-provider-alibaba-cloud

  1. Overview of cloud-provider-alibaba-cloud

    master
    The cloud-provider-alibaba-cloud is an external Kubernetes Cloud Controller Manager (CCM) implementation specifically for Alibaba Cloud. By running this provider, you enable your Kubernetes clusters to leverage various Alibaba Cloud services and integrate with the Alibaba Cloud infrastructure.
  2. Configure URL path matching policies for ALB Ingress

    master

    ALB Ingress supports three pathType values for matching URL paths:

    1. Exact: Matches the URL path exactly, including case sensitivity.
    2. ImplementationSpecific: The default policy. For ALB Ingresses, this has the same effect as the Exact policy.
    3. Prefix: Matches based on a URL path prefix separated by forward slashes (/). The match is case-sensitive and performed on each element of the path.
    # Example of Prefix matching
    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      annotations:
        alb.ingress.kubernetes.io/vswitch-ids: "vsw-2zeqgkyib34gw1fxs****,vsw-2zefv5qwao4przzlo****"
        kubernetes.io/ingress.class: alb
      name: demo-path-prefix
      namespace: default
    spec:
      rules:
        - http:
            paths:
              - path: /
                backend:
                  serviceName: demo-service
                  servicePort: 80
                pathType: Prefix
  3. Configure Session Stickiness (Persistence) for LoadBalancer

    master

    Session stickiness is supported for both TCP and HTTP/HTTPS listeners.

    For TCP Listeners

    Use service.beta.kubernetes.io/alibaba-cloud-loadbalancer-persistence-timeout to set the timeout in seconds (0-3600).

    For HTTP & HTTPS Listeners

    You must provide the following mandatory annotations:

    • service.beta.kubernetes.io/alibaba-cloud-loadbalancer-sticky-session: "on"
    • service.beta.kubernetes.io/alibaba-cloud-loadbalancer-sticky-session-type: Either insert (inserts a cookie) or server (rewrites a cookie).
    • service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: The protocol and port (e.g., http:80).
    • If using insert, you must set service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cookie-timeout (1–8640 seconds).
    • If using server, you must set service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cookie (the cookie name).
    # HTTP Insert Cookie Example
    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-sticky-session: "on"
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-sticky-session-type: "insert"
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-cookie-timeout: "1800"
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-protocol-port: "http:80"
      name: nginx
      namespace: default
    spec:
      ports:
      - port: 80
        protocol: TCP
        targetPort: 80
      selector:
        run: nginx
      type: LoadBalancer
  4. Implement canary releases with ALB Ingress

    master

    ALB supports canary releases using annotations. To enable canary functionality, you must set alb.ingress.kubernetes.io/canary: "true".

    Canary rules are applied in the following priority order: header-based > cookie-based > weight-based.

    Canary Methods

    1. Header-based: Uses alb.ingress.kubernetes.io/canary-by-header (the header name) and alb.ingress.kubernetes.io/canary-by-header-value (the expected value). If the header matches, traffic goes to the canary version.
    2. Cookie-based: Uses alb.ingress.kubernetes.io/canary-by-cookie.
      • Set value to always: Requests matching the rule go to the canary version.
      • Set value to never: Requests matching the rule go to the old version.
    3. Weight-based: Uses alb.ingress.kubernetes.io/canary-weight with a percentage value (0-100) to split traffic between versions.
  5. Force overwrite LoadBalancer listeners

    master

    If your cloud-controller-manager version is v1.9.3 or greater, the provider will not manage your existing LoadBalancer listeners by default. To force the provider to overwrite existing listeners, use the following annotation:

    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true"

    metadata:
      annotations:
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true"
  6. How ALB Ingress and Albconfig objects work together

    master

    The Alibaba Cloud Application Load Balancer (ALB) Ingress controller uses AlbConfig CustomResourceDefinition (CRD) objects to manage ALB instances and listeners.

    Relationship Model

    • Service: An abstraction of an application deployed on pods.
    • Ingress: Contains reverse proxy rules (hosts and URLs) to route traffic to Services.
    • AlbConfig: A CRD object that corresponds to exactly one ALB instance. It is used to configure that instance's listeners and settings.
    • Mapping: An AlbConfig object can be associated with multiple Ingress resources, allowing multiple Ingresses to share a single ALB instance.

    Lifecycle

    When an Ingress is created, the controller automatically generates an AlbConfig object named default in the kube-system namespace. The controller then performs these operations in sequence:

    1. Create ALB instances
    2. Configure listeners
    3. Create Ingress rules
    4. Configure backend server groups.
  7. Get started with cloud-provider-alibaba-cloud

    master

    To begin using the Alibaba Cloud cloud provider, refer to the following guides:

    • Getting Started: Detailed initial setup instructions can be found in docs/getting-started.md.
    • Usage Guide: For operational guidance and how to use the provider in a cluster, see docs/usage.md.
  8. Set up a Kubernetes Cluster using kubeadm

    master

    To use kubeadm with the Alibaba Cloud CloudProvider, you must configure the kubelet to include the provider ID and set the cloud provider to external.

    1. Configure Kubelet

    For each node, you must update the kubelet configuration to include --provider-id (formatted as region-id.instance-id) and --hostname-override.

    2. Initialize Cluster

    Use a kubeadm.conf file with the following requirements:

    • Set cloudProvider: external.
    • (Best Practice) Set imageRepository: registry-vpc.${region}.aliyuncs.com/acs to pull images faster within Alibaba Cloud regions.

    Run the initialization command:

    kubeadm init --config kubeadm.conf
    if [[ 0 -eq `grep '\--provider-id' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf|wc -l` ]]; then
      META_EP=http://100.100.100.200/latest/meta-data
      provider_id=`curl -s $META_EP/region-id`.`curl -s $META_EP/instance-id`
      sed -i "s/--cloud-provider=external/--cloud-provider=external --hostname-override=${provider_id} --provider-id=${provider_id}/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
      systemctl daemon-reload
      systemctl restart kubelet
    fi