

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 自訂 AMI 支援
<a name="custom-ami-support"></a>

## 設定節點 AMI ID
<a name="_setting_the_node_ami_id"></a>

`--node-ami` 旗標會啟用多種進階使用案例，例如使用自訂 AMI 或即時查詢 AWS，以判斷要使用的 AMI。旗標可用於非 GPU 和 GPU 映像。

旗標可以取得映像的 AMI 映像 ID 以明確使用。它也可以使用下列「特殊」關鍵字：


| 關鍵字 | Description | 
| --- | --- | 
|  auto  |  指出應該透過查詢 AWS EC2 找到用於節點的 AMI。這與自動解析程式相關。  | 
|  自動ssm  |  指出應該透過查詢 AWS SSM 參數存放區找到用於節點的 AMI。  | 

**注意**  
目前，EKS 受管節點群組在使用自訂 AMI 時僅支援下列 AMIs 系列：`AmazonLinux2023`、`AmazonLinux2`、`Bottlerocket`、`Ubuntu2004`、 `UbuntuPro2004``Ubuntu2204`和 `Ubuntu2404` 

`--node-ami` 將 設定為 ID 字串時， `eksctl`會假設已請求自訂 AMI。對於 AmazonLinux2 和 Ubuntu 節點，EKS 受管和自我管理，這表示`overrideBootstrapCommand`這是必要的。對於 AmazonLinux2023，由於`overrideBootstrapCommand`其停止將`/etc/eks/bootstrap.sh`指令碼用於節點引導，因此不支援節點廣告初始化程序 （如需詳細資訊，請參閱[節點引導文件](https://github.com/eksctl-io/eksctl/blob/main/pkg/nodebootstrap/README.md))。

CLI 旗標範例：

```
eksctl create cluster --node-ami=auto

# with a custom ami id
eksctl create cluster --node-ami=ami-custom1234
```

Config 檔案範例：

```
nodeGroups:
  - name: ng1
    instanceType: p2.xlarge
    amiFamily: AmazonLinux2
    ami: auto
  - name: ng2
    instanceType: m5.large
    amiFamily: AmazonLinux2
    ami: ami-custom1234
managedNodeGroups:
  - name: m-ng-2
    amiFamily: AmazonLinux2
    ami: ami-custom1234
    instanceType: m5.large
    overrideBootstrapCommand: |
      #!/bin/bash
      /etc/eks/bootstrap.sh <cluster-name>
```

`--node-ami` 旗標也可以與 搭配使用`eksctl create nodegroup`。

## 設定節點 AMI 系列
<a name="_setting_the_node_ami_family"></a>

`--node-ami-family` 可以採用下列關鍵字：


| 關鍵字 | Description | 
| --- | --- | 
|  AmazonLinux2  |  指出應使用以 Amazon Linux 2 為基礎的 EKS AMI 映像 （預設）。  | 
|  AmazonLinux2023  |  表示應使用以 Amazon Linux 2023 為基礎的 EKS AMI 映像。  | 
|  Ubuntu2004  |  表示應使用以 Ubuntu 20.04 LTS (Focal) 為基礎的 EKS AMI 映像 （支援 EKS ⇐ 1.29)。  | 
|  UbuntuPro2004  |  表示應使用以 Ubuntu Pro 20.04 LTS (Focal) 為基礎的 EKS AMI 映像 （適用於 EKS >= 1.27、⇐ 1.29)。  | 
|  Ubuntu2204  |  表示應使用以 Ubuntu 22.04 LTS (Jammy) 為基礎的 EKS AMI 映像 （適用於 EKS >= 1.29)。  | 
|  UbuntuPro2204  |  表示應使用以 Ubuntu Pro 22.04 LTS (Jammy) 為基礎的 EKS AMI 映像 （適用於 EKS >= 1.29)。  | 
|  Ubuntu2404  |  表示應使用以 Ubuntu 24.04 LTS (Noble) 為基礎的 EKS AMI 映像 （適用於 EKS >= 1.31)。  | 
|  UbuntuPro2404  |  表示應使用以 Ubuntu Pro 24.04 LTS (Noble) 為基礎的 EKS AMI 映像 （適用於 EKS >= 1.31)。  | 
|  Bottlerocket  |  指出應使用以 Bottlerocket 為基礎的 EKS AMI 映像。  | 
|  WindowsServer2019FullContainer  |  指出應使用以 Windows Server 2019 完整容器為基礎的 EKS AMI 映像。  | 
|  WindowsServer2019CoreContainer  |  表示應使用以 Windows Server 2019 Core Container 為基礎的 EKS AMI 映像。  | 
|  WindowsServer2022FullContainer  |  指出應使用以 Windows Server 2022 Full Container 為基礎的 EKS AMI 映像。  | 
|  WindowsServer2022CoreContainer  |  指出應使用以 Windows Server 2022 Core Container 為基礎的 EKS AMI 映像。  | 

CLI 旗標範例：

```
eksctl create cluster --node-ami-family=AmazonLinux2
```

Config 檔案範例：

```
nodeGroups:
  - name: ng1
    instanceType: m5.large
    amiFamily: AmazonLinux2
managedNodeGroups:
  - name: m-ng-2
    instanceType: m5.large
    amiFamily: Ubuntu2204
```

`--node-ami-family` 旗標也可以與 搭配使用`eksctl create nodegroup`。每當使用自訂 AMI 時， `eksctl` 需要透過組態檔案或透過 `--node-ami-family` CLI 旗標明確設定 AMI 系列。

**注意**  
目前，EKS 受管節點群組在使用自訂 AMI 時僅支援下列 AMIs 系列：`AmazonLinux2023`、`AmazonLinux2`、`Bottlerocket`、`Ubuntu2004`、 `UbuntuPro2004``Ubuntu2204`和 `Ubuntu2404` 

## Windows 自訂 AMI 支援
<a name="_windows_custom_ami_support"></a>

只有自我管理的 Windows 節點群組可以指定自訂 AMI。 `amiFamily` 應該設定為有效的 Windows AMI 系列。

引導指令碼將可使用下列 PowerShell 變數：

```
$EKSBootstrapScriptFile
$EKSClusterName
$APIServerEndpoint
$Base64ClusterCA
$ServiceCIDR
$KubeletExtraArgs
$KubeletExtraArgsMap: A hashtable containing arguments for the kubelet, e.g., @{ 'node-labels' = ''; 'register-with-taints' = ''; 'max-pods' = '10'}
$DNSClusterIP
$ContainerRuntime
```

Config 檔案範例：

```
nodeGroups:
  - name: custom-windows
    amiFamily: WindowsServer2022FullContainer
    ami: ami-01579b74557facaf7
    overrideBootstrapCommand: |
      & $EKSBootstrapScriptFile -EKSClusterName "$EKSClusterName" -APIServerEndpoint "$APIServerEndpoint" -Base64ClusterCA "$Base64ClusterCA" -ContainerRuntime "containerd" -KubeletExtraArgs "$KubeletExtraArgs" 3>&1 4>&1 5>&1 6>&1
```

## Bottlerocket 自訂 AMI 支援
<a name="_bottlerocket_custom_ami_support"></a>

對於 Bottlerocket 節點，`overrideBootstrapCommand`不支援 。相反地，若要指定自己的引導容器，應該使用 `bottlerocket` 欄位做為組態檔案的一部分。例如

```
  nodeGroups:
  - name: bottlerocket-ng
    ami: ami-custom1234
    amiFamily: Bottlerocket
    bottlerocket:
      enableAdminContainer: true
      settings:
        bootstrap-containers:
          bootstrap:
            source: <MY-CONTAINER-URI>
```