使用 Ubuntu 节点在 1.20 及更高版本上迁移的工作负载失败

AppArmor 允许系统管理员限制已部署容器的功能。如需部署迁移后的容器工作负载,Migrate to Containers 需要 Linux LXC 软件包提供的 AppArmor 配置文件。

但是,作为 Google Kubernetes Engine (GKE) 1.20 更新的一部分,Ubuntu 节点映像默认不再包含 LXC 软件包。这意味着使用 Ubuntu 节点的新部署集群或升级到 GKE 1.20 及更高版本的现有部署集群无法运行 Ubuntu 节点。

在 Ubuntu 节点上为 GKE 版本 1.20 及更高版本部署容器工作负载时,工作负载可以进入崩溃循环,并且日志包含错误消息,格式为:

D0806 01:59:15.000000 8 hcutil.py:136] SHELL CMD: aa-exec -p lxc-container-default echo 123
D0806 01:59:15.000000 8 hcutil.py:168] SHELL STDERR: b"aa-exec: ERROR: profile 'lxc-container-default' does not exist\n"
D0806 01:59:15.000000 8 hcutil.py:168] SHELL STDERR: b'\n'
D0806 01:59:15.000000 8 hcutil.py:210] SHELL COMPLETED: 1 (aa-exec -p lxc-container-default echo 123)
required AppArmor profile 'lxc-container-default' does not exist, if this pod runs on a
GKE node of type 'Container Optimized OS' (COS) please run
`migctl setup install --cos-runtime` to install it
E0806 01:59:15.000000    8 hcmain.py:22] Traceback (most recent call last):
  File "./hcmain.py", line 19, in safe_action
  File "./hcmain.py", line 74, in run_action
  File "./hcrunner.py", line 392, in validateSystem
Exception: Invalid system or AppArmor profile

E0806 01:59:15.000000 8 hcmain.py:23] Invalid system or AppArmor profile
I0806 01:59:15.000000 8 termination_log.py:4] writing error to termination log at /dev/termination-log

要解决此问题,请执行以下操作:

  1. 使用表单中的命令连接到部署集群:

    gcloud container clusters get-credentials CLUSTER --zone ZONE --project PROJECT
  2. 使用以下命令在部署集群上手动安装 Linux LXC 软件包:

    migctl setup install --cos-runtime