태그 보관물: package

The end of Kubernetes version 1.23 – Ubuntu kubernetes apt install error

2024년 3월 초, docker가 익숙해서 끝까지 버티고 있던 kubernetes v1.23.x 개발 환경 설치에 돌연 문제가 생겼다. Ubuntu에서 kubeadm, kubelet, kubectl 등을 apt로 설치할 수 없게 된 것이다. 원인과 해결 방법에 대해 알아보자.

Kubernetes apt install 에러 현상과 원인

K8s 설치 시 어떤 현상이 발생하는가?

2024년 3월 초부터 ubuntu에 apt install 명령어를 통해 kubeadm, kubelet, kubectl이 설치되지 않는다. 기존 사용하던 개발 환경은 다음과 같다.

OS: jharoian3/ubuntu-22.04-arm64
Kubernetes: 1.23.6-00
Docker: 5:24.0.6-1~ubuntu.22.04~jammy

설치를 위한 명령어는 다음과 같이 사용하고 있었다.

curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt -y install kubelet="$KUBERNETES_VERSION" kubectl="$KUBERNETES_VERSION" kubeadm="$KUBERNETES_VERSION"

위 명령어를 통해 kubernetes 설치를 진행하면, 다음과 같은 에러 메시지를 확인할 수 있다.

master: deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main
master: Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
master: Hit:3 http://ports.ubuntu.com/ubuntu-ports jammy InRelease
master: Ign:2 https://packages.cloud.google.com/apt kubernetes-xenial InRelease
master: Hit:4 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease
master: Err:5 https://packages.cloud.google.com/apt kubernetes-xenial Release
master:   404  Not Found [IP: 142.250.76.142 443]
master: Hit:6 http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease
master: Get:7 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease [110 kB]
master: Reading package lists...
master: E: The repository 'https://apt.kubernetes.io kubernetes-xenial Release' does not have a Release file.
master: 
master: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
master: 
master: Reading package lists...
master: Building dependency tree...
master: Reading state information...
master: E: Unable to locate package kubelet
master: E: Unable to locate package kubectl
master: E: Unable to locate package kubeadm

원인은 package repository에 있다!

위의 에러 메시지를 살펴보면, kubernetes 관련 package 목록을 가져오기 위해 package repository에 접속을 하는데, 404 에러가 발생하고 있음을 알 수 있다. 최근까지 잘 되던 것이 갑자기 되지 않으니까 당황스럽다. 원인은 외부에 있음을 직감하고, kubernetes 공식 문서들을 샅샅이 뒤져보았다.

아니나 다를까, package repository가 대체된다는 안내사항이 있었다. 해당 글에서는 다음과 같이 안내하고 있다.

On behalf of Kubernetes SIG Release, I am very excited to introduce the Kubernetes community-owned software repositories for Debian and RPM packages: pkgs.k8s.io! The new package repositories are replacement for the Google-hosted package repositories (apt.kubernetes.io and yum.kubernetes.io) that we’ve been using since Kubernetes v1.5.

ℹ️ Update (January 12, 2024): the legacy Google-hosted repositories are going away in January 2024. Check out the deprecation announcement for more details about this change.

기존 사용하던 package repository가 2024년 1월부터 아예 사라질 것이라고 되어 있는데, 3월까지 잘 사용한 것도 기적이었던 것이다. 평소 부지런하게 follow up하지 않았던 스스로를 반성하게 된다.

Package repository 관련 문제 해결 방법

Package repository deprecation에 대응하기

안내사항에 따르면, 다음과 같이 package repository를 변경한 후 apt install을 진행하면 된다.

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.23/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.23/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update

그런데, 이렇게 변경 후 테스트해도 여전히 다음과 같은 에러가 발생한다.

master: Reading package lists...
master: E: Failed to fetch https://pkgs.k8s.io/core:/stable:/v1.23/deb/InRelease  403  Forbidden [IP: 54.192.175.103 443]
master: E: The repository 'https://pkgs.k8s.io/core:/stable:/v1.23/deb  InRelease' is not signed.

한 걸음 나아가긴 했다. 404 Not Found 에러 대신 403 Forbidden 에러가 발생하는 것으로 보아, 적어도 새로운 package repository는 서비스를 하고 있긴 하다는 것을 확인할 수 있다. 그렇다면, 왜 이런 현상이 발생하는 것일까? 이 문제에 대한 원인도 앞서 언급한 안내 글에서 찾을 수 있었다.

The new Kubernetes package repositories contain packages beginning with those Kubernetes versions that were still under support when the community took over the package builds. This means that the new package repositories have Linux packages for all Kubernetes releases starting with v1.24.0.

새로운 package repository는 v1.24.0 이상의 kubernetes만 제공한다는 것이다. 결국, kubernetes의 버전을 올려야 한다.

Docker를 버린 kubernetes v1.24로의 여정

Kubernetes v1.23.x와 v1.24.x 사이에는 큰 차이점이 존재한다. Kubernetes v1.24.0부터는 docker를 버렸다는 것이다. 공식 문서의 내용을 간단히 요약하면 다음과 같다.

  • 1.24 버전 이전에는 docker라는 specific한 CRI를 사용하고 있었다.
  • Kubernetes에서 docker 외에도 다양한 CRI를 지원하기 위해, CRI standard라는 것을 만들었다.
  • Docker는 CRI standard를 따르지 않고 있다.
  • Kubernetes는 docker 지원을 위해 dockershim이라는 코드를 만들어서 제공했다.
  • Kubernetes 개발 참여자들이 docker라는 특수 CRI를 위해 별도로 시간을 할애하는 것이 부담스럽다.
  • Kubernetes v1.24부터 dockershim 지원 안하기로 했다.

실제로, kubernetes v1.24 버전을 설치할 때 docker를 사용하려고 하면, 다음과 같은 에러를 만날 수 있다.

master:     [WARNING SystemVerification]: missing optional cgroups: blkio
master: error execution phase preflight: [preflight] Some fatal errors occurred:
master:     [ERROR CRI]: container runtime is not running: output: time="2024-03-05T00:42:52-08:00" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
master: , error: exit status 1
master: [preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
master: To see the stack trace of this error execute with --v=5 or higher
master: failed to load admin kubeconfig: open /root/.kube/config: no such file or directory
master: To see the stack trace of this error execute with --v=5 or higher

눈물과 함께 kubernetes v1.23과 docker와 작별할 시간이다. 앞서 살펴본 package repository 설정 부분에서 버전을 지정해주는 문자열을 변경하자.

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.24/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.24/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update

이후 apt-cache policy kubeadm 명령어를 통해 설치 가능한 버전을 조회해보고 apt install을 통해 설치를 진행하면 된다. 이때 주의할 점은, docker가 아니라 containerd를 사용할 것이기 때문에 설치하려는 kubernetes 버전과 호환되는 containerd 버전을 알아보고 미리 설치해두어야 한다는 것이다. Containerd와 kubernetes 버전 호환 관계는 이 문서를 확인하면 된다.

최종적으로 정상화한 개발 환경은 다음과 같다.

OS: jharoian3/ubuntu-22.04-arm64
Kubernetes: 1.24.17-1.1
Containerd: 1.7.0

간단하게 요약하면?

요약 정리

  • 현상: ubuntu에 apt install로 kubernetes를 설치할 때, package list를 불러오는 과정에서 에러 발생
  • 원인: 2024년 초부터 버려진 legacy package repository를 참조하고 있을 가능성 있음
  • 해결책: 새로운 package repository로 변경하면 됨

주의사항

  • 새로운 package repository는 kubernetes v1.24.0 이상만 제공
  • Docker를 쓰고 있었다면, containerd같은 다른 CRI로 변경 필요

How to disable packages from automatically updating in Ubuntu

apt-mark 명령어는 패키지의 속성을 변경하는 데 사용됩니다. 주로 패키지를 hold 상태로 설정하거나 해당 설정을 해제하는 데에 사용됩니다.

1. Hold 설정

지정된 패키지를 현재 설치된 버전으로 고정시키고 업그레이드를 방지합니다

sudo apt-mark hold nginx
$ sudo apt-mark hold nginx
nginx set on hold.

2. Hold 상태 확인

Hold로 설정된 패키지 목록을 확인합니다.

sudo apt-mark showhold
$ sudo apt-mark showhold
nginx

3. Hold 해제

Hold 설정을 해제하여 패키지가 다시 업그레이드될 수 있도록 합니다.

sudo apt-mark unhold nginx
$ sudo apt-mark unhold nginx
Canceled hold on nginx.

4. 자동 설치 설정

패키지를 자동 설치로 표시합니다. 이렇게 하면 해당 패키지는 다른 패키지가 삭제될 때 자동으로 제거되지 않습니다.

sudo apt-mark auto nginx
$ sudo apt-mark auto nginx
nginx set to automatically installed.

5. 자동 설치 해제

패키지를 수동 설치로 표시합니다. 이렇게 하면 해당 패키지는 다른 패키지가 삭제될 때 자동으로 제거되지 않습니다.

sudo apt-mark manual nginx
$ sudo apt-mark manual nginx
nginx set to manually installed.

6. 수동 설치 확인

수동 설치된 패키지 목록을 표시합니다.(특정 패키지가 Hold로 설정되어 있는지 확인합니다.)

apt-mark showmanual
$ sudo apt-mark showmanual
nginx
php8.1
php8.1-cli
php8.1-common
php8.1-fpm
php8.1-gd
php8.1-imagick
php8.1-intl
php8.1-mbstring
php8.1-mongodb
php8.1-mysql
php8.1-rdkafka
php8.1-readline
php8.1-redis
php8.1-xml
php8.1-zip
software-properties-common
sudo apt-mark showmanual | grep nginx
$ sudo apt-mark showmanual | grep nginx
nginx
sudo apt-mark showhold | grep nginx
$ sudo apt-mark showhold | grep nginx

7. 자동 설치 확인

자동 설치된 패키지 목록을 표시합니다.

sudo apt-mark showauto
$ sudo apt-mark showauto
adduser
apache2
apache2-bin
apache2-data
apache2-utils
apt
apt-utils
bzip2
ca-certificates
coreutils
dbus
...
util-linux
uuid-runtime
xdg-user-dirs
xz-utils
zlib1g

8. 도움말 표시

apt-mark 명령어의 도움말을 표시합니다.

sudo apt-mark --help
$ sudo apt-mark --help
apt 2.4.11 (amd64)
Usage: apt-mark [options] {auto|manual} pkg1 [pkg2 ...]

apt-mark is a simple command line interface for marking packages
as manually or automatically installed. It can also be used to
manipulate the dpkg(1) selection states of packages, and to list
all packages with or without a certain marking.

Most used commands:
  auto - Mark the given packages as automatically installed
  manual - Mark the given packages as manually installed
  minimize-manual - Mark all dependencies of meta packages as automatically installed.
  hold - Mark a package as held back
  unhold - Unset a package set as held back
  showauto - Print the list of automatically installed packages
  showmanual - Print the list of manually installed packages
  showhold - Print the list of packages on hold

See apt-mark(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).