5

I am trying to install Kubernetes (kubectl) on Ubuntu 16.04 (x64) by following the instructions here. I am behind some proxy at work and I am sure that is the reason for the failure. I know there are a bunch of related questions out there but I have already tried any suggestion I could find. Any help will be greatly appreciated.

Currently, I am stuck at getting apt update to work. It is failing with -

W: The repository 'https://apt.kubernetes.io kubernetes-xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch https://apt.kubernetes.io/dists/kubernetes-xenial/main/binary-amd64/Packages  server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

I have tried multiple things here - Updated my apt.conf(at /etc/apt/apt.conf) with

Acquire::https::packages.cloud.google.com::Verify-Peer "false";

I also tried by specifying the above as a command line argument -

sudo apt-get update -o Acquire::https::packages.cloud.google.com::Verify-Peer=false

I have tried running apt-get update with --allow-unauthenticated & --allow-insecure-repositories but somehow apt-secure is still ignoring all these instructions. I went through the man-page for apt-secure but couldn't find anything wrong with the options I specified.

I have updated keys using -

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 6A030B21BA07F4FB

I have updated my CA certs. I have ran - sudo rm /var/lib/apt/lists/* to remove all the lists.

Contents of /etc/apt/sources.list.d/kubernetes.list

deb https://apt.kubernetes.io/ kubernetes-xenial main
muru
  • 197,895
  • 55
  • 485
  • 740

3 Answers3

14

There will be a redirection issue sometimes.

Use the source below will solve this.

deb http://packages.cloud.google.com/apt/ kubernetes-xenial main

Update in 2024.3.28: use a new URL.

deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /

Get the gpg key if absent:

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

The official document is here. It works for me.

Quote from Installing kubeadm:

Note: The legacy package repositories (apt.kubernetes.io and yum.kubernetes.io) have been deprecated and frozen starting from September 13, 2023. Using the new package repositories hosted at pkgs.k8s.io is strongly recommended and required in order to install Kubernetes versions released after September 13, 2023. The deprecated legacy repositories, and their contents, might be removed at any time in the future and without a further notice period. The new package repositories provide downloads for Kubernetes versions starting with v1.24.0.

3

For Amogh and Guru,

The reason this doesn't work anymore, as of January 31st 2024, is that K8s changed repo locations. See https://kubernetes.io/blog/2023/08/15/pkgs-k8s-io-introduction/#how-to-migrate

To deal with this, I have:

1.) removed the old source

which was: /etc/apt/sources.list.d/apt_kubernetes_io.list which contained

deb https://apt.kubernetes.io/ kubernetes-xenial main

2.) added the new source See their directions above, but short version is:

echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

sudo apt-get update

note the new repos ARE version sensitive, and you need to set the version appropriately. The above is for v1.28

2

For latest ubuntu version where deb command is not found

sudo apt-add-repository 'deb http://packages.cloud.google.com/apt/ kubernetes-xenial main

And for any errors for the packages add the gpg key

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

and then execute

sudo apt-get update
ravi.zombie
  • 171
  • 1
  • 4
  • this is works great on ubuntu 22 ! better than official documentation on kubernetes website (https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) – Rexave Nov 29 '22 at 16:37