-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkubectl.sh
More file actions
executable file
·29 lines (24 loc) · 949 Bytes
/
Copy pathkubectl.sh
File metadata and controls
executable file
·29 lines (24 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
check_kubectl() {
if command -v kubectl &> /dev/null; then
echo "kubectl is already installed. Version: $(kubectl version --client | grep 'Client Version')"
return 0
else
return 1
fi
}
install_kubectl() {
echo "kubectl is not installed. Installing now..."
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "Verifying kubectl download..."
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check || { echo "Error: kubectl download verification failed"; exit 1; }
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
rm -f kubectl kubectl.sha256
echo "kubectl installation completed."
}
if ! check_kubectl; then
install_kubectl
else
echo "No action needed. kubectl is already installed."
fi