I ran into the apt-key
deprecation problem and warnings while adding the kubernetes-xenial repo using a gpg key available online. I was working in an Ubuntu 22.04.1 environment on Apple Silicon (M1/aarch64/arm64). The solution provided below is very similar to the one proposed by Vamsi Nerella elsewhere in this thread, but it includes an explicit example--along with the creation of a new keyring directory ('/etc/apt/keyrings').
This solution also avoids any use of the '/etc/apt/trusted.gpg.d' keyring directory, which some sources have said does nothing to remedy the problem that led to the deprecation of apt-key
in the first place.
Although the packages added at the end of this example were from Kubernetes, this approach should work equally well with other packages, as Vamsi discussed.
This solution is also quite similar to the one proposed by Promise Preston (see thread), but it includes a reference to the system architecture, which I needed for my application. Perhaps others will benefit from this example.
Instead of this:
Create a 'kubernetes.list' file using a text editor such as vim or nano:
sudo vim /etc/apt/sources.list.d/kubernetes.list
Add the following text to the new file:
deb http://apt.kubernetes.io/ kubernetes-xenial main
Download the gpg key and use the deprecated apt-key
to enable the use of the new repo:
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
sudo apt-get update
sudo apt-get install kubeadm kubelet kubectl
Use this:
sudo mkdir -p /etc/apt/keyrings
sudo curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg
sudo echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/keyrings/kubernetes.gpg] \
http://apt.kubernetes.io/ kubernetes-xenial main" \
| sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null
sudo apt-get update
sudo apt-get install kubeadm kubelet kubectl
If you need a particular version of the Kubernetes packages, such as 1.26 (rather than the latest), you could do this in the last step:
sudo apt-get install -y kubelet=1.26.0-00 kubeadm=1.26.0-00 kubectl=1.26.0-00
As previously mentioned, you could substitute a different key for the one used in this example ('https://packages.cloud.google.com/apt/doc/apt-key.gpg'). The choice of 'kubernetes.gpg' in the dearmored key was arbitrary.
References: