1. 程式人生 > >製作ACK叢集自定義節點映象的正確姿勢

製作ACK叢集自定義節點映象的正確姿勢

隨著雲原生時代的到來,使用者應用、業務上雲的需求也越來越多,不同的業務場景對容器平臺的需求也不盡相同,其中一個非常重要的需求就是使用自定義映象建立ACK叢集。

ACK支援使用者使用自定義映象建立Kubernetes叢集,但使用者在製作打包自定義映象時,往往會遇到以下痛點:
(1)人工操作步驟,效率低
(2)映象變更歷史記錄缺失,不便於故障定位
(3)無法對自定義映象進行校驗並判斷是否符合ACK叢集節點要求

基於以上痛點,我們開源了ack-image-builder專案幫助使用者快速製作符合ACK叢集節點要求的自定義映象。

ack-image-builder專案基於開源工具HashiCorp Packer

,提供預設配置模板和校驗指令碼。

使用ack-image-builder專案建立ACK叢集自定義節點映象的步驟如下:

1. 安裝Packer

官方下載頁面選擇作業系統對應的軟體版本,並按照安裝說明文件安裝和驗證packer。

$ packer version
Packer v1.4.1

說明packer已安裝成功。

2. 定義Packer模板

使用Packer建立自定義映象時,需要建立一個JSON格式的模板檔案。在該模板檔案中,您需要指定建立自定義映象的 Alicloud Image Builder(生成器) 和 Provisioners(配置器)

{
  "variables": {
    "region": "cn-hangzhou",
    "image_name": "test_image{{timestamp}}",
    "source_image": "centos_7_06_64_20G_alibase_20190711.vhd",
    "instance_type": "ecs.n1.large",
    "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`}}",
      "io_optimized": "true"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "scripts": [
        "scripts/updateKernel.sh",
        "scripts/reboot.sh",
        "scripts/cleanUpKerneles.sh",
        "config/default.sh",
        "scripts/updateDNS.sh",
        "scripts/verify.sh"
      ],
      "expect_disconnect": true
    }
  ]
}
引數 描述
access_key 您的AccessKeyID
secret_key 您的AccessKeySecret
region 建立自定義映象時使用臨時資源的地域
image_name 自定義映象的名稱
source_image 基礎映象的名稱,可以從阿里雲公共映象列表獲得
instance_type 建立自定義映象時生成的臨時例項的型別
provisioners 建立自定義映象時使用的 Packer 配置器 型別

3. 建立子賬號並生成AK

製作自定義映象的許可權要求較大,一般建議使用者建立子賬戶並授權Packer需要的對應RAM Policy,並建立AK

4. 匯入AK資訊並製作自定義映象

匯入AK:

export ALICLOUD_ACCESS_KEY=XXXXXX
export ALICLOUD_SECRET_KEY=XXXXXX

製作自定義映象:

$ packer build alicloud.json
alicloud-ecs output will be in this color.

==> alicloud-ecs: Prevalidating source region and copied regions...
==> alicloud-ecs: Prevalidating image name...
    alicloud-ecs: Found image ID: centos_7_06_64_20G_alibase_20190711.vhd
==> alicloud-ecs: Creating temporary keypair: xxxxxx
==> alicloud-ecs: Creating vpc...
    alicloud-ecs: Created vpc: xxxxxx
==> alicloud-ecs: Creating vswitch...
    alicloud-ecs: Created vswitch: xxxxxx
==> alicloud-ecs: Creating security group...
    alicloud-ecs: Created security group: xxxxxx
==> alicloud-ecs: Creating instance...
    alicloud-ecs: Created instance: xxxxxx
==> alicloud-ecs: Allocating eip...
    alicloud-ecs: Allocated eip: xxxxxx
    alicloud-ecs: Attach keypair xxxxxx to instance: xxxxxx
==> alicloud-ecs: Starting instance: xxxxxx
==> alicloud-ecs: Using ssh communicator to connect: 47.111.127.54
==> alicloud-ecs: Waiting for SSH to become available...
==> alicloud-ecs: Connected to SSH!
==> alicloud-ecs: Provisioning with shell script: scripts/verify.sh
    alicloud-ecs: [20190726 11:04:10]: Check if kernel version >= 3.10.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if systemd version >= 219.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if sshd is running and listen on port 22.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if cloud-init is installed.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if wget is installed.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if curl is installed.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if kubeadm is cleaned up.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if kubelet is cleaned up.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if kubectl is cleaned up.  Verify Passed!
    alicloud-ecs: [20190726 11:04:10]: Check if kubernetes-cni is cleaned up.  Verify Passed!
==> alicloud-ecs: Stopping instance: xxxxxx
==> alicloud-ecs: Waiting instance stopped: xxxxxx
==> alicloud-ecs: Creating image: test_image1564110199
    alicloud-ecs: Detach keypair xxxxxx from instance: xxxxxxx
==> alicloud-ecs: Cleaning up 'EIP'
==> alicloud-ecs: Cleaning up 'instance'
==> alicloud-ecs: Cleaning up 'security group'
==> alicloud-ecs: Cleaning up 'vSwitch'
==> alicloud-ecs: Cleaning up 'VPC'
==> alicloud-ecs: Deleting temporary keypair...
Build 'alicloud-ecs' finished.

==> Builds finished. The artifacts of successful builds are:
--> alicloud-ecs: Alicloud images were created:

cn-hangzhou: m-bp1aifbnupnaktj00q7s

其中scripts/verify.sh為對檢查項的校驗部分。

5. 使用自定義映象建立ACK叢集

登入容器服務控制檯,選擇建立 Kubernetes 專有版 叢集, 配置叢集建立需要的相關基礎資訊後,點開 顯示高階選項 並選擇自定義映象進行叢集建立。


原文連結
本文為雲棲社群原創內容,未經