Kubectl (kubernetes) does not install with the install-script.sh

Following the instructions in the DevSecOps course, section 2 (Demo – Installing software in VM), after creating and connecting to the VM via SSH. The install-script.sh does not work as expected. Kubernetes fails to install. I get the following error messages:

E: The repository ‘http://apt.kubernetes.io kubernetes-xenial Release’ does not have a Release
file.
N: Updating from such a repository can’t be done securely, and is therefore disabled by default
N: See apt-secure(8) manpage for repository creation and user configuration details.
Reading package lists… Done

E: Unable to locate package kubectl
E: Unable to locate package kubernetes-cni
E: Unable to locate package kubeadm
install-script.sh: line 21: pip3: command not found
install-script.sh: line 25: jc: command not found
install-script.sh: line 25: jq: command not found
install-script.sh: line 27: /etc/docker/daemon.json: No such file or directory
Failed to restart docker.service: Unit docker.service not found.
Failed to enable unit: Unit file docker.service does not exist.
Failed to enable unit: Unit file kubelet.service does not exist.
Failed to start kubelet.service: Unit kubelet.service not found.

KUBERNETES-.-._.#################--------------

rm: cannot remove ‘/root/.kube/config’: No such file or directory
install-script.sh: line 44: kubeadm: command not found
install-script.sh: line 48: kubeadm: command not found
cp: cannot stat ‘/etc/kubernetes/admin.conf’: No such file or directory
install-script.sh: line 53: kubectl: command not found
untaint controlplane node
install-script.sh: line 58: kubectl: command not found
install-script.sh: line 58: kubectl: command not found
install-script.sh: line 59: kubectl: command not found
install-script.sh: line 59: kubectl: command not found
install-script.sh: line 60: kubectl: command not found

I am unable to continue with the course as a result of the above issue.
Thanks,

This script is currently being updated. A newer version should be published to the github repo sometime in the coming week.

1 Like

Please try the updated version. I have updated both the install script and the Azure Template.

Please download the repo to your laptop using the following commands

git clone https://github.com/kodekloudhub/kubernetes-devops-security.git
cd kubernetes-devops-security
git checkout ubuntu-2204

Then use the template and install.sh from your local copy.

1 Like

Many thanks Alistair, this worked.

Splendid!

I will merge that change so it becomes current.

Note also that it includes a slightly newer version of Jenkins, so the Jenkins UI might look a little different to what it shown in the videos. It should still work the same though.

Also the Kubernetes version is upgraded to 1.29 (latest), but that should not cause any issues.

Hi, It didnt fix the issue for me. Kubectl command not found. See screenshot

Please help

Did you

  1. Use the correct repo?
  2. Run the install script as root?

Like this…

# Become root
sudo -i

# Clone repo
git clone https://github.com/kodekloudhub/devsecops.git

# CD to script directory
cd devsecops/setup/vm-install-script/

# Install
./install-script.sh

Then …

root@ip-172-31-20-248:~/devsecops/setup/vm-install-script# kubectl get pods -A
NAMESPACE     NAME                                       READY   STATUS    RESTARTS       AGE
kube-system   coredns-7db6d8ff4d-5hsgq                   1/1     Running   0              3m14s
kube-system   coredns-7db6d8ff4d-jwhmq                   1/1     Running   0              3m14s
kube-system   etcd-ip-172-31-20-248                      1/1     Running   0              3m28s
kube-system   kube-apiserver-ip-172-31-20-248            1/1     Running   0              3m28s
kube-system   kube-controller-manager-ip-172-31-20-248   1/1     Running   0              3m30s
kube-system   kube-proxy-x97n7                           1/1     Running   0              3m14s
kube-system   kube-scheduler-ip-172-31-20-248            1/1     Running   0              3m29s
kube-system   weave-net-pljgg                            2/2     Running   1 (3m7s ago)   3m14s
root@ip-172-31-20-248:~/devsecops/setup/vm-install-script#

It and fixed my smell! Thanks a lot!