日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

彈性優(yōu)化之自定義鏡像

Alicloud Image Builder是阿里云推出的一款鏡像構(gòu)建工具,旨在通過簡易的方式自動化構(gòu)建鏡像。利用Alicloud Image Builder構(gòu)建出的操作系統(tǒng)鏡像,再結(jié)合ACK集群節(jié)點池的自定義鏡像功能,可以快速地擴容節(jié)點。本文介紹如何在ACK集群中利用Alicloud Image Builder通過Job的方式構(gòu)建自定義操作系統(tǒng)鏡像。

前提條件

為什么需要彈性優(yōu)化的自定義鏡像

ACK集群的節(jié)點池支持ACK集群節(jié)點的彈性伸縮,默認創(chuàng)建節(jié)點池時,提供的操作系統(tǒng)鏡像包括Alibaba Cloud Linux、CentOS等操作系統(tǒng)鏡像,已經(jīng)能夠滿足絕大多數(shù)場景的使用。但是在一些預安裝或者高性能場景下,原有的基礎鏡像并不能滿足我們的需求。阿里云提供的Alicloud Image Builder,可以幫助您構(gòu)建屬于自己的自定義操作系統(tǒng)鏡像,從而提高復雜場景下彈性伸縮的便捷性。

使用Alicloud Image Builder創(chuàng)建自定義鏡像時,您可以通過Job或CronJob將鏡像構(gòu)建任務下發(fā)到集群完成構(gòu)建。

使用ACK Job快速構(gòu)建自定義操作系統(tǒng)鏡像

本文通過創(chuàng)建名為build-config的配置項和名為build的Job工作負載為例,說明如何使用Alicloud Image Builder快速構(gòu)建自定義操作系統(tǒng)鏡像。

1、配置構(gòu)建操作系統(tǒng)鏡像的參數(shù)

您可以創(chuàng)建名為build-config的配置項,以配置構(gòu)建操作系統(tǒng)鏡像的參數(shù)。

  1. 使用以下YAML內(nèi)容創(chuàng)建名為build-config.yaml的文件。

    展開查看YAML詳情

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: build-config
    data:
      ack.json: |-
    
        {
          "variables": {
            "image_name": "ack-optimized_image-1.30-{{timestamp}}",
            "source_image": <source_image>,
            "instance_type": <instance_type>,
            "region": "{{env `ALICLOUD_REGION`}}",
            "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
            "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
          },
          "builders": [
            {
              "type": "alicloud-ecs",
              "system_disk_mapping": {    
                        "disk_size": 120
                        },   # 指定鏡像系統(tǒng)盤大小,單位為G。默認為40G。
              "access_key": "{{user `access_key`}}",
              "secret_key": "{{user `secret_key`}}",
              "region": "{{user `region`}}",
              "image_name": "{{user `image_name`}}",
              "source_image": "{{user `source_image`}}",
              "ssh_username": "root",
              "vpc_id": "",  # 不指定vpc_id時,流程會新建此資源,流程結(jié)束后自動清理。
              "vswitch_id": "",  # 不指定vswitch_id時,流程會新建此資源,流程結(jié)束后自動清理。
              "security_group_id": "",   # 不指定security_group_id時,流程會新建此資源,流程結(jié)束后自動清理。
              "instance_type": "{{user `instance_type`}}",
              "skip_image_validation": "true",
              "io_optimized": "true"
            }
          ],
          "provisioners": [{
           "type": "file",
           "source": "scripts/ack-optimized-os-all.sh",
           "destination": "/root/"
            },
            {
           "type": "shell",
           "inline": [
             "export RUNTIME=containerd",    # 根據(jù)Runtime填寫。
             "export RUNTIME_VERSION=1.6.28",
             "export SKIP_SECURITY_FIX=true",
             "export KUBE_VERSION=1.30.1-aliyun.1",
             "export OS_ARCH=amd64",    # 根據(jù)需求選擇amd64或者arm64。
             "bash /root/ack-optimized-os-all.sh"
          ]
          }]
        }

    上述YAML中涉及參數(shù)解釋如下。

    表 1. Alicloud Image Builder配置文件的參數(shù)解釋

    參數(shù)

    示例值

    描述

    variables{"<variable1>":"<value>"}

    variables{"access_key":"{{env ALICLOUD_ACCESS_KEY}}"}

    定義了Alicloud Image Builder中會用到的變量(variables)。

    說明

    如果將重要信息,例如AccessKey(包括access_keysecret_key)寫入配置文件的話,存在信息泄露的風險,但是將其設置成變量后可防止意外,變量的值來源于運行時的輸入值。

    builders{"type":"<value>"}

    builders{"type":"alicloud-ecs"}

    鏡像生成器(builders)。當設置typealiyun-ecs時,表示構(gòu)建鏡像時,會臨時創(chuàng)建一個ECS實例來完成鏡像構(gòu)建。構(gòu)建完成后,ECS實例會自動銷毀。

    provisioners{"type":"<value>"}

    provisioners{"type":"shell"}

    鏡像配置器(provisioners),用以定義需要在臨時實例內(nèi)執(zhí)行的操作。當設置typeshell時,說明使用的是Shell Provisioner,表示在連接Linux實例后自動執(zhí)行一段Shell命令。例如,執(zhí)行Shell命令yum install redis.x86_64 -y安裝Redis。

    關于Provisioner配置的更多信息,請參見下文的Provisioner配置介紹

    表 2. 鏡像構(gòu)建涉及的參數(shù)解釋

    參數(shù)

    示例值

    描述

    是否必填

    access_key

    LTAInPyXXXXQ****

    您的AccessKey ID。更多詳情,請參見獲取AccessKey

    必填

    secret_key

    CM1ycKrrCekQ0dhXXXXXXXXXl7y****

    您的AccessKey Secret。

    必填

    region

    cn-beijing

    目標自定義鏡像的所屬地域。

    必填

    image_name

    ack-custom_image

    目標自定義鏡像的名稱。不允許與已有鏡像重名。

    必填

    source_image

    aliyun_2_1903_x64_20G_alibase_20200904.vhd

    具有相同操作系統(tǒng)的阿里云公共鏡像ID。詳細信息,請參見容器服務Kubernetes版支持的操作系統(tǒng)鏡像

    必填

    instance_type

    ecs.c6.xlarge

    以source_image為鏡像生成實例運行指定的預安裝任務然后生成自定義鏡像。如需要GPU類型鏡像此處需要填寫GPU類型的實例。

    必填

    RUNTIME

    containerd

    容器運行時,Docker或者containerd。

    必填

    RUNTIME_VERSION

    1.6.28

    • 容器運行時為Docker時,默認RUNTIME_VERSION為19.03.15。

    • 容器運行時為containerd時,默認RUNTIME_VERSION為1.6.20。

    選填

    SKIP_SECURITY_FIX

    true

    跳過安全更新。

    必填

    KUBE_VERSION

    1.30.1-aliyun.1

    集群版本號。

    必填

    PRESET_GPU

    true

    預置安裝GPU,加速啟動。

    選填

    NVIDIA_DRIVER_VERSION

    460.91.03

    預置GPU版本,不填默認為460.91.03。

    選填

    OS_ARCH

    amd64

    CPU架構(gòu),amd64或者arm64。

    必填

    MOUNT_RUNTIME_DATADISK

    true

    自定義鏡像緩存了業(yè)務鏡像后,如需在使用過程中為ECS實例掛數(shù)據(jù)盤,則配置為true。

    選填

    重要
    • 為節(jié)點池配置自定義鏡像前,請確認節(jié)點池的相關配置(集群版本、容器運行時、GPU版本適配機型)與構(gòu)建自定義鏡像時的相關配置一致,否則會導致節(jié)點無法加入集群。

    • 自定義鏡像驗證階段使用和所選參數(shù)匹配的普通節(jié)點池驗證即可,成功加入節(jié)點池后在業(yè)務上驗證是否正常。

  2. 執(zhí)行以下命令部署Alicloud Image Builder到集群。

    kubectl apply -f build-config.yaml

2、創(chuàng)建Job以完成自定義操作系統(tǒng)鏡像的構(gòu)建

  1. 使用以下YAML內(nèi)容為AK、SK授予相關權(quán)限。

    展開查看YAML詳情

    {
      "Version": "1",
      "Statement": [
        {
          "Action": [
            "ecs:DeleteInstance",
            "ecs:StartInstance",
            "ecs:StopInstance",
            "ecs:DescribeInstances"
          ],
          "Resource": "*",
          "Effect": "Allow"
        },
        {
          "Action": [
            "ecs:CreateInstance",
            "ecs:DescribeImages",
            "ecs:CreateImage",
            "ecs:ModifyImageSharePermission",
            "ecs:CreateKeyPair",
            "ecs:DeleteKeyPairs",
            "ecs:DetachKeyPair",
            "ecs:AttachKeyPair",
            "ecs:CreateSecurityGroup",
            "ecs:DeleteSecurityGroup",
            "ecs:AuthorizeSecurityGroupEgress",
            "ecs:AuthorizeSecurityGroup",
            "ecs:CreateSnapshot",
            "ecs:AttachDisk",
            "ecs:DetachDisk",
            "ecs:DescribeDisks",
            "ecs:CreateDisk",
            "ecs:DeleteDisk",
            "ecs:CreateNetworkInterface",
            "ecs:DescribeNetworkInterfaces",
            "ecs:AttachNetworkInterface",
            "ecs:DetachNetworkInterface",
            "ecs:DeleteNetworkInterface",
            "ecs:DescribeInstanceAttribute"
          ],
          "Resource": "*",
          "Effect": "Allow"
        },
        {
          "Action": [
            "vpc:DescribeVpcs",
            "vpc:DescribeVSwitches",
            "vpc:AllocateEipAddress",
            "vpc:AssociateEipAddress",
            "vpc:UnassociateEipAddress",
            "vpc:DescribeEipAddresses",
            "vpc:ReleaseEipAddress",
            "vpc:CreateVpc",
            "vpc:DeleteVpc",
            "vpc:DescribeVpcs",
            "vpc:CreateVSwitch",
            "vpc:DeleteVSwitch",
            "vpc:DescribeVSwitches",
            "vpc:CreateRouteTable",
            "vpc:DeleteRouteTable",
            "vpc:DescribeRouteTables",
            "vpc:CreateNatGateway",
            "vpc:DeleteNatGateway",
            "vpc:DescribeNatGateways",
            "vpc:CreateSnatEntry",
            "vpc:DeleteSnatEntry",
            "vpc:DescribeSnatTableEntries"
          ],
          "Resource": "*",
          "Effect": "Allow"
        }
      ]
    }
  2. 使用以下命令生成AK、SK加密字符串。

    echo -n "AKxxxxxxxxxxxxxxx" | base64
    echo -n "SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | base64
  3. 使用以下YAML內(nèi)容創(chuàng)建my-secret。

    apiVersion: v1
    kind: Secret
    metadata:
      name: my-secret
      namespace: default
    type: Opaque
    data:
      ALICLOUD_ACCESS_KEY: TFRxxxxxxxxxxxxxRTkx      // 上一步經(jīng)過base64加密后的字符串
      ALICLOUD_SECRET_KEY: a0zxxxxxxxxxxxxxx2UThl
  4. 使用以下YAML內(nèi)容創(chuàng)建名為build.yaml的文件。

    根據(jù)需求配置變量運行Job,過程中會用的source_image在AK、SK所在賬號下生成instance_type類型的ECS,然后運行provisioners的配置,運行完成后會將ECS生成鏡像推送到AK、SK所在賬號下指定REGION的自定義鏡像。

    展開查看YAML詳情

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: image-builder
      namespace: default
    spec:
      template:
        metadata:
          name: image-builder
        spec:
      template:
        metadata:
          name: image-builder
        spec:
          containers:
            - name: image-builder
              image: "registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/image-builder:v3.3"
              imagePullPolicy: Always
            env:            
             - name: ALICLOUD_ACCESS_KEY              
             	 valueFrom:                
            	   secretKeyRef:                  
           		     name: my-secret                  
                   key: ALICLOUD_ACCESS_KEY            
             - name: ALICLOUD_SECRET_KEY              
               valueFrom:                
                 secretKeyRef:                  
                   name: my-secret                  
                   key: ALICLOUD_SECRET_KEY            
             - name: ALICLOUD_REGION              
               value: cn-hangzhou   
              command: ["packer"]
              args:  ["build","/config/ack.json"]
              volumeMounts:
                - name: config
                  mountPath: /config
          volumes:
            - name: config
              configMap:
                name: build-config
                items:
                  - key: ack.json
                    path: ack.json
          restartPolicy: Never
  5. 執(zhí)行以下命令部署Job到集群開始構(gòu)建操作系統(tǒng)鏡像。

    kubectl apply -f build.yaml

3、(可選)查看自定義鏡像構(gòu)建日志

構(gòu)建鏡像時會產(chǎn)生操作日志。日志給出了構(gòu)建過程中執(zhí)行的每一個步驟,包括校驗參數(shù)、創(chuàng)建臨時資源、預安裝軟件、創(chuàng)建目標資源和釋放臨時資源等。您可以執(zhí)行以下步驟查看鏡像構(gòu)建日志。

  1. 登錄容器服務管理控制臺,在左側(cè)導航欄選擇集群

  2. 集群列表頁面,單擊目標集群名稱,然后在左側(cè)導航欄,選擇工作負載 > 任務

  3. 在任務列表中,找到上步創(chuàng)建的任務(Job),并單擊其右側(cè)操作列下的詳情

  4. 在目標任務詳情頁,單擊日志頁簽,然后查看鏡像構(gòu)建日志。

Provisioner配置介紹

Provisioner是在轉(zhuǎn)換為靜態(tài)操作系統(tǒng)鏡像之前,在正在運行的機器中用于安裝和配置軟件的組件。常用來被執(zhí)行安裝軟件到鏡像中的主要工作場景包括:

  • 安裝軟件包。

  • 修補內(nèi)核。

  • 創(chuàng)建用戶。

  • 下載應用程序代碼。

  • 制作Alibaba Cloud Linux 3自定義鏡像。

執(zhí)行Shell腳本

  "provisioners": [{
      "type": "shell",
      "script": "script.sh"
  }]

使用Ansible執(zhí)行編排腳本

  "provisioners": [
    {
    "type": "ansible",
    "playbook_file": "./playbook.yml"
    }
  ]

安裝CPFS客戶端

由于CPFS需要安裝的包較多,且一部分安裝包涉及現(xiàn)場編譯流程,安裝過程比較費時。在客戶端節(jié)點數(shù)量較大時,使用自定義鏡像可以極大減少批量安裝CPFS客戶端節(jié)點的成本。示例配置如下。

展開查看詳情

    {
      "variables": {
        "region": "{{env `ALICLOUD_REGION`}}",
        "image_name": "ack-custom_image",
        "source_image": "centos_7_04_64_20G_alibase_201701015.vhd",
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "instance_type": "ecs.c6.xlarge",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
    "builders": [
        {
          "type": "alicloud-ecs",
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "ssh_username": "root",
          "instance_type": "{{user `instance_type`}}",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
   "provisioners": [{
        "type": "shell",
        "inline": [
            "cd $HOME",
            "wget https://cpfs-client.oss-cn-beijing.aliyuncs.com/kernel/kernel-devel-`uname -r`.rpm",
            "rpm -ivh --replacefiles kernel-devel-`uname -r`.rpm"
        ]
      }]

定制Arm架構(gòu)鏡像

展開查看詳情

{
      "variables": {
        "region": "{{env `ALICLOUD_REGION`}}",
        "image_name": "ack-custom_image",
        "source_image": "aliyun_3_arm64_20G_alibase_20240528.vhd",
        "instance_type": "ecs.r8y.xlarge",   # 配置Arm架構(gòu)的實例類型。
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
    "builders": [
        {
          "type": "alicloud-ecs",
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "instance_type": "{{user `instance_type`}}",
          "ssh_username": "root",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
   "provisioners": [
        {
            "type": "file",
            "source": "scripts/ack-optimized-os-linux3-all.sh",
            "destination": "/root/"
        },
        {
            "type": "shell",
            "inline": [
                "export RUNTIME=containerd",
                "export SKIP_SECURITY_FIX=true",
                "export KUBE_VERSION=1.28.9-aliyun.1",
                "export OS_ARCH=arm64",
                "bash /root/ack-optimized-os-linux3-all.sh"
            ]
        }
      ]
    }

定制GPU節(jié)點系統(tǒng)鏡像,加速啟動

重要

自定義GPU鏡像和自定義CPU鏡像暫不支持混用。

展開查看詳情

{
      "variables": {
        "region": "{{env `ALICLOUD_REGION`}}",
        "image_name": "ack-custom_image",
        "source_image": "aliyun_2_1903_x64_20G_alibase_20221102.vhd",
        "instance_type": "ecs.gn6i-c4g1.xlarge",   # 預置GPU安裝需要設置GPU規(guī)格的類型。
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
    "builders": [
        {
          "type": "alicloud-ecs",
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "instance_type": "{{user `instance_type`}}",
          "ssh_username": "root",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
   "provisioners": [
        {
            "type": "file",
            "source": "scripts/ack-optimized-os-all.sh",
            "destination": "/root/"
        },
        {
            "type": "shell",
            "inline": [
                "export RUNTIME=containerd",
                "export SKIP_SECURITY_FIX=true",
                "export PRESET_GPU=true",          # 預置GPU安裝需要設置PRESET_GPU為true,不需要預置GPU時保持留空或設置為false。
                "export NVIDIA_DRIVER_VERSION=510.47.03",         # 設置GPU版本,留空則默認安裝460.91.03版本。
                "export KUBE_VERSION=1.22.3-aliyun.1",
                "export OS_ARCH=amd64",
                "bash /root/ack-optimized-os-all.sh"
            ]
        }
      ]
    }

將業(yè)務鏡像緩存到系統(tǒng)鏡像中

展開查看詳情

{
      "variables": {
        "image_name": "ack-custom_image",
        "source_image": "aliyun_3_x64_20G_alibase_20240528.vhd",
        "instance_type": "ecs.c6.xlarge",
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "region": "{{env `ALICLOUD_REGION`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
    "builders": [
        {
          "type": "alicloud-ecs",
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "instance_type": "{{user `instance_type`}}",
          "ssh_username": "root",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
   "provisioners": [
        {
            "type": "file",
            "source": "scripts/ack-optimized-os-linux3-all.sh",
            "destination": "/root/"
        },
        {
            "type": "shell",
            "inline": [
                "export RUNTIME=containerd",
                "export SKIP_SECURITY_FIX=true",
                "export KUBE_VERSION=1.30.1-aliyun.1",
                "export OS_ARCH=amd64",
                "bash /root/ack-optimized-os-linux3-all.sh",
                "ctr -n k8s.io i pull registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/pause:3.9"        # 將業(yè)務鏡像固化到系統(tǒng)鏡像中。
            ]
        }
      ]
    }

掛載了數(shù)據(jù)盤的ECS實例在加入節(jié)點池的過程中會經(jīng)歷磁盤初始化,預先緩存的業(yè)務鏡像會被清理。如果您使用自定義鏡像生成ECS時有掛載數(shù)據(jù)盤的需求,可以選擇在制作自定義鏡像的過程中生成數(shù)據(jù)盤快照,確保業(yè)務鏡像不會被清理。

{
      "variables": {
        "image_name": "ack-custom_image",
        "source_image": "aliyun_3_x64_20G_alibase_20240528.vhd",
        "instance_type": "ecs.c6.xlarge",
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "region": "{{env `ALICLOUD_REGION`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
    "builders": [
        {
          "type": "alicloud-ecs",
          "system_disk_mapping": {    
                    "disk_size": 120,
                    "disk_category": "cloud_essd"
                    },
          "image_disk_mappings": {
                    "disk_size": 40,
                    "disk_category": "cloud_auto"
                    },     # 制作自定義鏡像時配置數(shù)據(jù)盤,鏡像制作完成后將自動生成數(shù)據(jù)盤的快照。
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "instance_type": "{{user `instance_type`}}",
          "ssh_username": "root",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
   "provisioners": [
        {
            "type": "file",
            "source": "scripts/ack-optimized-os-linux3-all.sh",
            "destination": "/root/"
        },
        {
            "type": "shell",
            "inline": [
                "export RUNTIME=containerd",
                "export SKIP_SECURITY_FIX=true",
                "export KUBE_VERSION=1.30.1-aliyun.1",
                "export OS_ARCH=amd64",
                "export MOUNT_RUNTIME_DATADISK=true",     # 將容器運行時的文件路徑掛載到數(shù)據(jù)盤
                "bash /root/ack-optimized-os-linux3-all.sh",
                "ctr -n k8s.io i pull registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/pause:3.9",        # 將業(yè)務鏡像固化到系統(tǒng)鏡像中。
                "mv /var/lib/containerd /var/lib/container/containerd"       # 將鏡像文件移動到數(shù)據(jù)盤
            ]
        }
      ]
    }

配置節(jié)點池時,您可以配置包含數(shù)據(jù)盤快照的自定義鏡像,系統(tǒng)會自動關聯(lián)對應的數(shù)據(jù)盤快照。

image

Runtime為Docker時拉取私有倉庫鏡像

docker login <鏡像地址> -u user -p password
docker pull nginx

Runtime為containerd時拉取私有倉庫鏡像

ctr -n k8s.io i pull --user=username:password nginx

自定義鏡像構(gòu)建拉取私有倉庫鏡像

  1. 在已安裝完成Docker的Linux機器上,執(zhí)行如下docker login命令,生成證書。

    docker login --username=zhongwei.***@aliyun-test.com --password xxxxxxxxxx registry.cn-beijing.aliyuncs.com

    docker login成功后,會在/root/.docker下生成證書config.json。96

  2. 將生成的config.json文件制作成ConfigMap。

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: docker-config
    data:
      config.json: |-
    
        {
            "auths": {
                    "registry.cn-beijing.aliyuncs.com": {
                            "auth": "xxxxxxxxxxxxxx"
                    }
            },
            "HttpHeaders": {
                    "User-Agent": "Docker-Client/19.03.15 (linux)"
            }
    
        }
  3. 修改Job的YAML,將Configmap掛載到Pod中。95

    展開查看YAML詳情

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: image-builder
      namespace: default
    spec:
      template:
        metadata:
          name: image-builder
        spec:
          containers:
            - name: image-builder
              image: "registry.cn-hangzhou.aliyuncs.com/acs/image-builder:v2.9"
              imagePullPolicy: Always
              env:
                - name: ALICLOUD_ACCESS_KEY
                  value: xxxxxxxxxxxxxx
                - name: ALICLOUD_SECRET_KEY
                  value: xxxxxxxxxxxxx
                - name: ALICLOUD_REGION
                  value: cn-heyuan
              command: ["packer"]
              args:  ["build","/config/ack.json"]
              volumeMounts:
                - name: config
                  mountPath: /config
                - name: docker
                  mountPath: /dockerconfig
          volumes:
            - name: config
              configMap:
                name: build-config
                items:
                  - key: ack.json
                    path: ack.json
            - name: docker
              configMap:
                name: docker-config
                items:
                  - key: config.json
                    path: config.json
          restartPolicy: Never
  4. 修改build-config,增加圖中所示內(nèi)容。94

    展開查看詳情

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: build-config
    data:
      ack.json: |-
    
        {
          "variables": {
            "image_name": "ack-optimized_image-1.20-{{timestamp}}",
            "source_image": "aliyun_2_1903_x64_20G_alibase_20221102.vhd",
            "instance_type": "ecs.c6.xlarge",
            "region": "{{env `ALICLOUD_REGION`}}",
            "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
            "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
          },
          "builders": [
            {
              "type": "alicloud-ecs",
              "access_key": "{{user `access_key`}}",
              "secret_key": "{{user `secret_key`}}",
              "region": "{{user `region`}}",
              "image_name": "{{user `image_name`}}",
              "source_image": "{{user `source_image`}}",
              "ssh_username": "root",
              "instance_type": "{{user `instance_type`}}",
              "skip_image_validation": "true",
              "io_optimized": "true"
            }
          ],
          "provisioners": [{
           "type": "file",
           "source": "scripts/ack-optimized-os-all.sh",
           "destination": "/root/"
            },
            {
           "type": "file",
           "source": "dockerconfig/config.json",
           "destination": "/root/"
            },
            {
           "type": "shell",
           "inline": [
             "export OS_ARCH=amd64",
             "export RUNTIME=docker",
             "export SKIP_SECURITY_FIX=true",
             "export KUBE_VERSION=1.22.15-aliyun.1",
             "bash /root/ack-optimized-os-all.sh",
             "mkdir -p /root/.docker",
             "cp /root/config.json /root/.docker",
             "docker pull registry.cn-beijing.aliyuncs.com/ringtail/kruise-game:0.1"
    
          ]
          }]
        }
  5. 執(zhí)行Job。

設置鏡像上傳、下載并發(fā)數(shù)

  1. 登錄容器服務管理控制臺,在左側(cè)導航欄單擊集群

  2. 集群列表頁面,單擊目標集群名稱,然后在左側(cè)導航欄,選擇節(jié)點管理 > 節(jié)點池

  3. 單擊目標節(jié)點池名稱,然后單擊基本信息頁簽,在節(jié)點池信息區(qū)域,單擊彈性伸縮 ESS 伸縮組 的鏈接。

  4. 單擊實例配置來源頁簽,然后在操作列單擊目標伸縮配置右側(cè)的修改,單擊確定

  5. 修改伸縮配置頁面,修改相關配置項并展開高級設置,記錄實例自定義數(shù)據(jù)區(qū)域的內(nèi)容。使用Base64編碼方式解密實例自定義數(shù)據(jù)框中的數(shù)據(jù)。

  6. 解密完成后,將以下代碼加入解密后代碼的后面。

    yum install -y jq
    echo "$jq '. += {"max-concurrent-downloads": 20,"max-concurrent-uploads": 20}' /etc/docker/daemon.json" > /etc/docker/daemon.json
    service docker restart

    加

  7. 使用Base64編碼方式加密合成的代碼,用加密后的代碼替換原來實例自定義數(shù)據(jù)框中的代碼,單擊修改,然后單擊確認修改

制作Alibaba Cloud Linux 3自定義鏡像

展開查看詳情

apiVersion: v1
kind: ConfigMap
metadata:
  name: build-config
data:
  ack.json: |-
    
    {
      "variables": {
        "image_name": "ack-optimized_image-1.22-{{timestamp}}",
        "source_image":"aliyun_3_x64_20G_alibase_20230110.vhd",  # Alibaba Cloud Linux 3的基礎鏡像。
        "instance_type": "ecs.c6.xlarge",
        "region": "{{env `ALICLOUD_REGION`}}",
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}",
      },
      "builders": [
        {
          "type": "alicloud-ecs",
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "ssh_username": "root",  
          "instance_type": "{{user `instance_type`}}",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
      "provisioners": [{
       "type": "file",
       "source": "scripts/ack-optimized-os-linux3-all.sh",
       "destination": "/root/"
        },
        {
       "type": "shell",
       "inline": [
         "export RUNTIME=containerd",
         "export SKIP_SECURITY_FIX=true",
         "export OS_ARCH=amd64",
         "export KUBE_VERSION=1.22.3-aliyun.1",
         "bash /root/ack-optimized-os-linux3-all.sh",
      ]
      }]
    }

制作Red Hat Enterprise Linux 9自定義鏡像

展開查看詳情

apiVersion: v1
kind: ConfigMap
metadata:
  name: build-config
data:
  ack.json: |-
    
    {
      "variables": {
        "image_name": "ack-optimized_image-1.26-{{timestamp}}",
        "source_image": "m-bp1c7zuf8mcabc99babc",       # RHEL9的基礎鏡像。
        "instance_type": "ecs.c6.xlarge",
        "region": "{{env `ALICLOUD_REGION`}}",
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}",
        "runtime": "{{env `RUNTIME`}}",
        "skip_secrutiy_fix": "{{env `SKIP_SECURITY_FIX`}}"
      },
      "builders": [
        {
          "type": "alicloud-ecs",
          "access_key": "{{user `access_key`}}",
          "secret_key": "{{user `secret_key`}}",
          "region": "{{user `region`}}",
          "image_name": "{{user `image_name`}}",
          "source_image": "{{user `source_image`}}",
          "ssh_username": "root",
          # "vpc_id": "",
          # "vswitch_id": "",
          # "security_group_id": "",      
          "instance_type": "{{user `instance_type`}}",
          "skip_image_validation": "true",
          "io_optimized": "true"
        }
      ],
      "provisioners": [{
       "type": "file",
       "source": "scripts/ack-optimized-os-rhel9-all.sh",
       "destination": "/root/"
        },
        {
       "type": "shell",
       "inline": [
         "export RUNTIME=containerd",
         "export SKIP_SECURITY_FIX=true",
         "export OS_ARCH=amd64",
         "export KUBE_VERSION=1.26.3-aliyun.1",
         "bash /root/ack-optimized-os-rhel9-all.sh"
      ]
      }]
    }

相關操作