在执行 apt update 之前,Cloud Init 不会添加 Apt 源

在执行 apt update 之前,Cloud Init 不会添加 Apt 源

我正在尝试从 docker 和 k8s.io 安装软件包,但package_update: true没有使用新添加的源,并且找不到这些软件包。

以下是 cloud-init 配置的一部分:

apt:
  sources:
    docker:
      keyid: '9DC858229FC7DD38854AE2D88D81803C0EBFCD88'
      keyserver: 'https://download.docker.com/linux/ubuntu/gpg'
      source: 'deb [signed-by=$KEY_FILE] https://download.docker.com/linux/ubuntu mantic stable'
    kubernetes:
      keyid: 'DE15B14486CD377B9E876E1A234654DA9A296436'
      keyserver: 'https://prod-cdn.packages.k8s.io/repositories/isv:/kubernetes:/core:/stable:/v1.28/deb/Release.key'
      source: 'deb [signed-by=$KEY_FILE] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /'
  conf: |
    APT {
        Get {
            Assume-Yes 'true';
            Fix-Broken 'true';
        }
    }
package_update: true
package_upgrade: false
packages:
  - apt-transport-https
  - ca-certificates
  - curl
  - gpg
  - gnupg
  - containerd.io
  - kubelet
  - kubeadm
  - kubectl

cloud-init-output.log

Cloud-init v. 23.3.1-0ubuntu2 running 'modules:config' at Sun, 10 Dec 2023 19:37:18 +0000. Up 12.34 seconds.
Get:1 http://security.ubuntu.com/ubuntu mantic-security InRelease [109 kB]
Get:2 http://archive.ubuntu.com/ubuntu mantic InRelease [256 kB]
Get:3 http://security.ubuntu.com/ubuntu mantic-security/main amd64 Packages [135 kB]
Get:4 http://security.ubuntu.com/ubuntu mantic-security/main Translation-en [40.5 kB]
Get:5 http://security.ubuntu.com/ubuntu mantic-security/main amd64 DEP-11 Metadata [7232 B]
Get:6 http://security.ubuntu.com/ubuntu mantic-security/main amd64 c-n-f Metadata [1560 B]
Get:7 http://security.ubuntu.com/ubuntu mantic-security/restricted amd64 Packages [150 kB]
Get:8 http://security.ubuntu.com/ubuntu mantic-security/restricted Translation-en [24.6 kB]
Get:9 http://security.ubuntu.com/ubuntu mantic-security/restricted amd64 c-n-f Metadata [420 B]
Get:10 http://security.ubuntu.com/ubuntu mantic-security/universe amd64 Packages [52.1 kB]
Get:11 http://security.ubuntu.com/ubuntu mantic-security/universe Translation-en [18.6 kB]
Get:12 http://security.ubuntu.com/ubuntu mantic-security/universe amd64 DEP-11 Metadata [3860 B]
Get:13 http://security.ubuntu.com/ubuntu mantic-security/universe amd64 c-n-f Metadata [788 B]
Get:14 http://security.ubuntu.com/ubuntu mantic-security/multiverse amd64 Packages [4284 B]
Get:15 http://security.ubuntu.com/ubuntu mantic-security/multiverse Translation-en [932 B]
Get:16 http://security.ubuntu.com/ubuntu mantic-security/multiverse amd64 c-n-f Metadata [232 B]
Get:17 http://archive.ubuntu.com/ubuntu mantic-updates InRelease [109 kB]
Get:18 http://archive.ubuntu.com/ubuntu mantic-backports InRelease [90.8 kB]
Get:19 http://archive.ubuntu.com/ubuntu mantic/main amd64 DEP-11 Metadata [465 kB]
Get:20 http://archive.ubuntu.com/ubuntu mantic/universe amd64 Packages [15.2 MB]
Get:21 http://archive.ubuntu.com/ubuntu mantic/universe Translation-en [5951 kB]
Get:22 http://archive.ubuntu.com/ubuntu mantic/universe amd64 DEP-11 Metadata [3793 kB]
Get:23 http://archive.ubuntu.com/ubuntu mantic/universe amd64 c-n-f Metadata [303 kB]
Get:24 http://archive.ubuntu.com/ubuntu mantic/multiverse amd64 Packages [239 kB]
Get:25 http://archive.ubuntu.com/ubuntu mantic/multiverse Translation-en [113 kB]
Get:26 http://archive.ubuntu.com/ubuntu mantic/multiverse amd64 DEP-11 Metadata [31.6 kB]
Get:27 http://archive.ubuntu.com/ubuntu mantic/multiverse amd64 c-n-f Metadata [8356 B]
Get:28 http://archive.ubuntu.com/ubuntu mantic-updates/main amd64 Packages [170 kB]
Get:29 http://archive.ubuntu.com/ubuntu mantic-updates/main Translation-en [52.3 kB]
Get:30 http://archive.ubuntu.com/ubuntu mantic-updates/main amd64 DEP-11 Metadata [7240 B]
Get:31 http://archive.ubuntu.com/ubuntu mantic-updates/main amd64 c-n-f Metadata [1676 B]
Get:32 http://archive.ubuntu.com/ubuntu mantic-updates/restricted amd64 Packages [153 kB]
Get:33 http://archive.ubuntu.com/ubuntu mantic-updates/restricted Translation-en [25.0 kB]
Get:34 http://archive.ubuntu.com/ubuntu mantic-updates/restricted amd64 c-n-f Metadata [420 B]
Get:35 http://archive.ubuntu.com/ubuntu mantic-updates/universe amd64 Packages [72.3 kB]
Get:36 http://archive.ubuntu.com/ubuntu mantic-updates/universe Translation-en [26.3 kB]
Get:37 http://archive.ubuntu.com/ubuntu mantic-updates/universe amd64 DEP-11 Metadata [3864 B]
Get:38 http://archive.ubuntu.com/ubuntu mantic-updates/universe amd64 c-n-f Metadata [820 B]
Get:39 http://archive.ubuntu.com/ubuntu mantic-updates/multiverse amd64 Packages [4284 B]
Get:40 http://archive.ubuntu.com/ubuntu mantic-updates/multiverse Translation-en [932 B]
Get:41 http://archive.ubuntu.com/ubuntu mantic-updates/multiverse amd64 c-n-f Metadata [232 B]
Get:42 http://archive.ubuntu.com/ubuntu mantic-backports/main amd64 c-n-f Metadata [112 B]
Get:43 http://archive.ubuntu.com/ubuntu mantic-backports/restricted amd64 c-n-f Metadata [116 B]
Get:44 http://archive.ubuntu.com/ubuntu mantic-backports/universe amd64 Packages [3928 B]
Get:45 http://archive.ubuntu.com/ubuntu mantic-backports/universe Translation-en [1392 B]
Get:46 http://archive.ubuntu.com/ubuntu mantic-backports/universe amd64 c-n-f Metadata [116 B]
Get:47 http://archive.ubuntu.com/ubuntu mantic-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 27.6 MB in 5s (5384 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
0 upgraded, 0 newly installed, 0 to remove and 50 not upgraded.
Cloud-init v. 23.3.1-0ubuntu2 running 'modules:final' at Sun, 10 Dec 2023 19:37:28 +0000. Up 22.09 seconds.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'
E: Unable to locate package kubelet
E: Unable to locate package kubeadm
E: Unable to locate package kubectl

/var/log/cloud-init.log(相关条目):

2023-12-10 20:29:41,050 - helpers.py[DEBUG]: Running update-sources using lock (<FileLock using file '/var/lib/cloud/instances/i-bf7816b90d424023a2255369dc5b7609/sem/update_sources'>)
2023-12-10 20:29:47,970 - util.py[DEBUG]: apt-update [eatmydata apt-get --option=Dpkg::Options::=--force-confold --option=Dpkg::options::=--force-unsafe-io --assume-yes --quiet update] took 6.919 seconds
2023-12-10 20:29:48,221 - cc_apt_configure.py[DEBUG]: adding source/key '{'keyid': '9DC858229FC7DD38854AE2D88D81803C0EBFCD88', 'keyserver': 'https://download.docker.com/linux/ubuntu/gpg', 'source': 'deb [signed-by=$KEY_FILE] https://download.docker.com/linux/ubuntu mantic stable'}'
2023-12-10 20:29:48,514 - cc_apt_configure.py[DEBUG]: adding source/key '{'keyid': 'DE15B14486CD377B9E876E1A234654DA9A296436', 'keyserver': 'https://prod-cdn.packages.k8s.io/repositories/isv:/kubernetes:/core:/stable:/v1.28/deb/Release.key', 'source': 'deb [signed-by=$KEY_FILE] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /'}'
2023-12-10 20:29:48,907 - helpers.py[DEBUG]: update-sources already ran (freq=once-per-instance)

VM 的/etc/cloud/cloud.cfg订单:

cloud_config_modules:
  - apt_pipelining
  - apt_configure
cloud_final_modules:
  - package_update_upgrade_install

从虚拟机:

创建来源

vagrant@ubuntu:~$ sudo ls /etc/apt/sources.list.d
docker.list  kubernetes.list

手动更新时,发现源:

vagrant@ubuntu:~$ sudo apt update
Get:1 https://download.docker.com/linux/ubuntu mantic InRelease [48.8 kB]
Hit:2 http://archive.ubuntu.com/ubuntu mantic InRelease                                                   
Hit:3 http://security.ubuntu.com/ubuntu mantic-security InRelease                          
Get:4 https://download.docker.com/linux/ubuntu mantic/stable amd64 Packages [2926 B]       
Hit:5 http://archive.ubuntu.com/ubuntu mantic-updates InRelease                                
Hit:7 http://archive.ubuntu.com/ubuntu mantic-backports InRelease   
Get:6 https://prod-cdn.packages.k8s.io/repositories/isv:/kubernetes:/core:/stable:/v1.28/deb  InRelease [1186 B]
Get:8 https://prod-cdn.packages.k8s.io/repositories/isv:/kubernetes:/core:/stable:/v1.28/deb  Packages [7750 B]
Fetched 60.7 kB in 1s (48.2 kB/s)   
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
50 packages can be upgraded. Run 'apt list --upgradable' to see them.

安装containerd.io

$ sudo apt install containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  containerd.io
0 upgraded, 1 newly installed, 0 to remove and 50 not upgraded.
Need to get 28.7 MB of archives.
After this operation, 117 MB of additional disk space will be used.
Get:1 https://download.docker.com/linux/ubuntu mantic/stable amd64 containerd.io amd64 1.6.25-1 [28.7 MB]
Fetched 28.7 MB in 1s (25.4 MB/s)        
Selecting previously unselected package containerd.io.
(Reading database ... 65188 files and directories currently installed.)
Preparing to unpack .../containerd.io_1.6.25-1_amd64.deb ...
Unpacking containerd.io (1.6.25-1) ...
Setting up containerd.io (1.6.25-1) ...

Configuration file '/etc/containerd/config.toml'
 ==> File on system created by you or by a script.
 ==> File also in package provided by package maintainer.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** config.toml (Y/I/N/O/D/Z) [default=N] ? N
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Processing triggers for man-db (2.11.2-3) ...
Scanning processes...                                                                                                                                                                                                                                    
Scanning linux images...                                                                                                                                                                                                                                 

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

相关内容