Skip to content

Commit a5630c5

Browse files
authored
Merge pull request #25259 from nate-double-u/25040-sha256-checks
Updating install-kubectl.md with instructions for validating kubectl binaries against checksum files
2 parents 58f2248 + ac8b4c5 commit a5630c5

File tree

1 file changed

+152
-52
lines changed

1 file changed

+152
-52
lines changed

content/en/docs/tasks/tools/install-kubectl.md

Lines changed: 152 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,73 @@ Using the latest version of kubectl helps avoid unforeseen issues.
3232

3333
1. Download the latest release with the command:
3434

35-
```
36-
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
37-
```
35+
```bash
36+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
37+
```
3838

39-
To download a specific version, replace the `$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)` portion of the command with the specific version.
39+
{{< note >}}
40+
To download a specific version, replace the `$(curl -L -s https://dl.k8s.io/release/stable.txt)` portion of the command with the specific version.
4041

41-
For example, to download version {{< param "fullversion" >}} on Linux, type:
42-
43-
```
44-
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/linux/amd64/kubectl
45-
```
42+
For example, to download version {{< param "fullversion" >}} on Linux, type:
4643

47-
2. Make the kubectl binary executable.
44+
```bash
45+
curl -LO https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/linux/amd64/kubectl
46+
```
47+
{{< /note >}}
4848

49-
```
50-
chmod +x ./kubectl
51-
```
49+
1. Validate the binary (optional)
5250

53-
3. Move the binary in to your PATH.
51+
Download the kubectl checksum file:
5452

55-
```
56-
sudo mv ./kubectl /usr/local/bin/kubectl
57-
```
58-
4. Test to ensure the version you installed is up-to-date:
53+
```bash
54+
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
55+
```
5956

60-
```
61-
kubectl version --client
62-
```
57+
Validate the kubectl binary against the checksum file:
58+
59+
```bash
60+
echo "$(<kubectl.sha256) kubectl" | sha256sum --check
61+
```
62+
63+
If valid, the output is:
64+
65+
```bash
66+
kubectl: OK
67+
```
68+
69+
If the check fails, `sha256` exits with nonzero status and prints output similar to:
70+
71+
```bash
72+
kubectl: FAILED
73+
sha256sum: WARNING: 1 computed checksum did NOT match
74+
```
75+
76+
{{< note >}}
77+
Download the same version of the binary and checksum.
78+
{{< /note >}}
79+
80+
1. Install kubectl
81+
82+
```bash
83+
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
84+
```
85+
86+
{{< note >}}
87+
If you do not have root access on the target system, you can still install kubectl to the `~/.local/bin` directory:
88+
89+
```bash
90+
mkdir -p ~/.local/bin/kubectl
91+
mv ./kubectl ~/.local/bin/kubectl
92+
# and then add ~/.local/bin/kubectl to $PATH
93+
```
94+
95+
{{< /note >}}
96+
97+
1. Test to ensure the version you installed is up-to-date:
98+
99+
```bash
100+
kubectl version --client
101+
```
63102

64103
### Install using native package management
65104

@@ -120,30 +159,65 @@ kubectl version --client
120159
1. Download the latest release:
121160

122161
```bash
123-
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl"
162+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
124163
```
125164

126-
To download a specific version, replace the `$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)` portion of the command with the specific version.
165+
{{< note >}}
166+
To download a specific version, replace the `$(curl -L -s https://dl.k8s.io/release/stable.txt)` portion of the command with the specific version.
127167

128168
For example, to download version {{< param "fullversion" >}} on macOS, type:
129169

130170
```bash
131-
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl
171+
curl -LO https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl
172+
```
173+
174+
{{< /note >}}
175+
176+
1. Validate the binary (optional)
177+
178+
Download the kubectl checksum file:
179+
180+
```bash
181+
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256"
132182
```
133183

134-
Make the kubectl binary executable.
184+
Validate the kubectl binary against the checksum file:
185+
186+
```bash
187+
echo "$(<kubectl.sha256) kubectl" | shasum -a 256 --check
188+
```
189+
190+
If valid, the output is:
191+
192+
```bash
193+
kubectl: OK
194+
```
195+
196+
If the check fails, `shasum` exits with nonzero status and prints output similar to:
197+
198+
```bash
199+
kubectl: FAILED
200+
shasum: WARNING: 1 computed checksum did NOT match
201+
```
202+
203+
{{< note >}}
204+
Download the same version of the binary and checksum.
205+
{{< /note >}}
206+
207+
1. Make the kubectl binary executable.
135208

136209
```bash
137210
chmod +x ./kubectl
138211
```
139212

140-
3. Move the binary in to your PATH.
213+
1. Move the kubectl binary to a file location on your system `PATH`.
141214

142215
```bash
143-
sudo mv ./kubectl /usr/local/bin/kubectl
216+
sudo mv ./kubectl /usr/local/bin/kubectl && \
217+
sudo chown root: /usr/local/bin/kubectl
144218
```
145219

146-
4. Test to ensure the version you installed is up-to-date:
220+
1. Test to ensure the version you installed is up-to-date:
147221

148222
```bash
149223
kubectl version --client
@@ -165,7 +239,7 @@ If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you
165239
brew install kubernetes-cli
166240
```
167241

168-
2. Test to ensure the version you installed is up-to-date:
242+
1. Test to ensure the version you installed is up-to-date:
169243

170244
```bash
171245
kubectl version --client
@@ -182,7 +256,7 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
182256
sudo port install kubectl
183257
```
184258

185-
2. Test to ensure the version you installed is up-to-date:
259+
1. Test to ensure the version you installed is up-to-date:
186260

187261
```bash
188262
kubectl version --client
@@ -192,47 +266,72 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
192266

193267
### Install kubectl binary with curl on Windows
194268

195-
1. Download the latest release {{< param "fullversion" >}} from [this link](https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe).
269+
1. Download the [latest release {{< param "fullversion" >}}](https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe).
196270

197271
Or if you have `curl` installed, use this command:
198272

199-
```bash
200-
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe
273+
```powershell
274+
curl -LO https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe
201275
```
202276

203-
To find out the latest stable version (for example, for scripting), take a look at [https://storage.googleapis.com/kubernetes-release/release/stable.txt](https://storage.googleapis.com/kubernetes-release/release/stable.txt).
277+
{{< note >}}
278+
To find out the latest stable version (for example, for scripting), take a look at [https://dl.k8s.io/release/stable.txt](https://dl.k8s.io/release/stable.txt).
279+
{{< /note >}}
204280

205-
2. Add the binary in to your PATH.
281+
1. Validate the binary (optional)
206282

207-
3. Test to ensure the version of `kubectl` is the same as downloaded:
283+
Download the kubectl checksum file:
208284

209-
```bash
285+
```powershell
286+
curl -LO https://dl.k8s.io/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe.sha256
287+
```
288+
289+
Validate the kubectl binary against the checksum file:
290+
291+
- Using Command Prompt to manually compare `CertUtil`'s output to the checksum file downloaded:
292+
293+
```cmd
294+
CertUtil -hashfile kubectl.exe SHA256
295+
type kubectl.exe.sha256
296+
```
297+
298+
- Using PowerShell to automate the verification using the `-eq` operator to get a `True` or `False` result:
299+
300+
```powershell
301+
$($(CertUtil -hashfile .\kubectl.exe SHA256)[1] -replace " ", "") -eq $(type .\kubectl.exe.sha256)
302+
```
303+
304+
1. Add the binary in to your `PATH`.
305+
306+
1. Test to ensure the version of `kubectl` is the same as downloaded:
307+
308+
```cmd
210309
kubectl version --client
211310
```
212311

213312
{{< note >}}
214-
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to PATH.
215-
If you have installed Docker Desktop before, you may need to place your PATH entry before the one added by the Docker Desktop installer or remove the Docker Desktop's `kubectl`.
313+
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to `PATH`.
314+
If you have installed Docker Desktop before, you may need to place your `PATH` entry before the one added by the Docker Desktop installer or remove the Docker Desktop's `kubectl`.
216315
{{< /note >}}
217316

218-
### Install with Powershell from PSGallery
317+
### Install with PowerShell from PSGallery
219318

220-
If you are on Windows and using [Powershell Gallery](https://www.powershellgallery.com/) package manager, you can install and update kubectl with Powershell.
319+
If you are on Windows and using the [PowerShell Gallery](https://www.powershellgallery.com/) package manager, you can install and update kubectl with PowerShell.
221320

222321
1. Run the installation commands (making sure to specify a `DownloadLocation`):
223322

224323
```powershell
225324
Install-Script -Name 'install-kubectl' -Scope CurrentUser -Force
226325
install-kubectl.ps1 [-DownloadLocation <path>]
227-
```
326+
```
228327

229328
{{< note >}}
230-
If you do not specify a `DownloadLocation`, `kubectl` will be installed in the user's temp Directory.
329+
If you do not specify a `DownloadLocation`, `kubectl` will be installed in the user's `temp` Directory.
231330
{{< /note >}}
232331

233332
The installer creates `$HOME/.kube` and instructs it to create a config file.
234333

235-
2. Test to ensure the version you installed is up-to-date:
334+
1. Test to ensure the version you installed is up-to-date:
236335

237336
```powershell
238337
kubectl version --client
@@ -260,32 +359,32 @@ Updating the installation is performed by rerunning the two commands listed in s
260359
{{< /tabs >}}
261360

262361

263-
2. Test to ensure the version you installed is up-to-date:
362+
1. Test to ensure the version you installed is up-to-date:
264363

265364
```powershell
266365
kubectl version --client
267366
```
268367

269-
3. Navigate to your home directory:
368+
1. Navigate to your home directory:
270369

271370
```powershell
272371
# If you're using cmd.exe, run: cd %USERPROFILE%
273372
cd ~
274373
```
275374

276-
4. Create the `.kube` directory:
375+
1. Create the `.kube` directory:
277376

278377
```powershell
279378
mkdir .kube
280379
```
281380

282-
5. Change to the `.kube` directory you just created:
381+
1. Change to the `.kube` directory you just created:
283382

284383
```powershell
285384
cd .kube
286385
```
287386

288-
6. Configure kubectl to use a remote Kubernetes cluster:
387+
1. Configure kubectl to use a remote Kubernetes cluster:
289388

290389
```powershell
291390
New-Item config -type file
@@ -301,13 +400,13 @@ You can install kubectl as part of the Google Cloud SDK.
301400

302401
1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/).
303402

304-
2. Run the `kubectl` installation command:
403+
1. Run the `kubectl` installation command:
305404

306405
```shell
307406
gcloud components install kubectl
308407
```
309408

310-
3. Test to ensure the version you installed is up-to-date:
409+
1. Test to ensure the version you installed is up-to-date:
311410

312411
```shell
313412
kubectl version --client
@@ -385,11 +484,13 @@ You now need to ensure that the kubectl completion script gets sourced in all yo
385484
```bash
386485
echo 'source <(kubectl completion bash)' >>~/.bashrc
387486
```
487+
388488
- Add the completion script to the `/etc/bash_completion.d` directory:
389489

390490
```bash
391491
kubectl completion bash >/etc/bash_completion.d/kubectl
392492
```
493+
393494
If you have an alias for kubectl, you can extend shell completion to work with that alias:
394495

395496
```bash
@@ -470,7 +571,6 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
470571

471572
```bash
472573
echo 'source <(kubectl completion bash)' >>~/.bash_profile
473-
474574
```
475575

476576
- Add the completion script to the `/usr/local/etc/bash_completion.d` directory:

0 commit comments

Comments
 (0)