Skip to content

Commit f124c3b

Browse files
committed
start install-kubectl-linux
1 parent 15487e7 commit f124c3b

File tree

1 file changed

+348
-0
lines changed

1 file changed

+348
-0
lines changed
Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
1+
---
2+
title: Instalar y Configurar kubectl en Linux
3+
content_type: task
4+
weight: 10
5+
---
6+
7+
## {{% heading "prerequisites" %}}
8+
9+
Se debe utilizar la version de kubectl con una minor version de diferencia con
10+
su cluster. Por ejemplo, un cliente con version v{{< skew currentVersion >}} se puede comunicar
11+
con los siguientes versiones de plano de control v{{< skew currentVersionAddMinor -1 >}},
12+
v{{< skew currentVersionAddMinor 0 >}}, and v{{< skew currentVersionAddMinor 1 >}}.
13+
Utilizar la ultima version compatible de kubectl evita posibles errores.
14+
15+
## Install kubectl on Linux
16+
17+
The following methods exist for installing kubectl on Linux:
18+
19+
- [Install kubectl binary with curl on Linux](#install-kubectl-binary-with-curl-on-linux)
20+
- [Install using native package management](#install-using-native-package-management)
21+
- [Install using other package management](#install-using-other-package-management)
22+
23+
### Install kubectl binary with curl on Linux
24+
25+
1. Download the latest release with the command:
26+
27+
{{< tabs name="download_binary_linux" >}}
28+
{{< tab name="x86-64" codelang="bash" >}}
29+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
30+
{{< /tab >}}
31+
{{< tab name="ARM64" codelang="bash" >}}
32+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
33+
{{< /tab >}}
34+
{{< /tabs >}}
35+
36+
{{< note >}}
37+
To download a specific version, replace the `$(curl -L -s https://dl.k8s.io/release/stable.txt)`
38+
portion of the command with the specific version.
39+
40+
For example, to download version {{< skew currentPatchVersion >}} on Linux x86-64, type:
41+
42+
```bash
43+
curl -LO https://dl.k8s.io/release/v{{< skew currentPatchVersion >}}/bin/linux/amd64/kubectl
44+
```
45+
46+
And for Linux ARM64, type:
47+
48+
```bash
49+
curl -LO https://dl.k8s.io/release/v{{< skew currentPatchVersion >}}/bin/linux/arm64/kubectl
50+
```
51+
52+
{{< /note >}}
53+
54+
1. Validate the binary (optional)
55+
56+
Download the kubectl checksum file:
57+
58+
{{< tabs name="download_checksum_linux" >}}
59+
{{< tab name="x86-64" codelang="bash" >}}
60+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
61+
{{< /tab >}}
62+
{{< tab name="ARM64" codelang="bash" >}}
63+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl.sha256"
64+
{{< /tab >}}
65+
{{< /tabs >}}
66+
67+
Validate the kubectl binary against the checksum file:
68+
69+
```bash
70+
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
71+
```
72+
73+
If valid, the output is:
74+
75+
```console
76+
kubectl: OK
77+
```
78+
79+
If the check fails, `sha256` exits with nonzero status and prints output similar to:
80+
81+
```console
82+
kubectl: FAILED
83+
sha256sum: WARNING: 1 computed checksum did NOT match
84+
```
85+
86+
{{< note >}}
87+
Download the same version of the binary and checksum.
88+
{{< /note >}}
89+
90+
1. Install kubectl
91+
92+
```bash
93+
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
94+
```
95+
96+
{{< note >}}
97+
If you do not have root access on the target system, you can still install
98+
kubectl to the `~/.local/bin` directory:
99+
100+
```bash
101+
chmod +x kubectl
102+
mkdir -p ~/.local/bin
103+
mv ./kubectl ~/.local/bin/kubectl
104+
# and then append (or prepend) ~/.local/bin to $PATH
105+
```
106+
107+
{{< /note >}}
108+
109+
1. Test to ensure the version you installed is up-to-date:
110+
111+
```bash
112+
kubectl version --client
113+
```
114+
115+
Or use this for detailed view of version:
116+
117+
```cmd
118+
kubectl version --client --output=yaml
119+
```
120+
121+
### Install using native package management
122+
123+
{{< tabs name="kubectl_install" >}}
124+
{{% tab name="Debian-based distributions" %}}
125+
126+
1. Update the `apt` package index and install packages needed to use the Kubernetes `apt` repository:
127+
128+
```shell
129+
sudo apt-get update
130+
# apt-transport-https may be a dummy package; if so, you can skip that package
131+
sudo apt-get install -y apt-transport-https ca-certificates curl
132+
```
133+
134+
2. Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:
135+
136+
```shell
137+
curl -fsSL https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
138+
```
139+
140+
3. Add the appropriate Kubernetes `apt` repository. If you want to use Kubernetes version different than {{< param "version" >}},
141+
replace {{< param "version" >}} with the desired minor version in the command below:
142+
143+
```shell
144+
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
145+
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
146+
```
147+
148+
{{< note >}}
149+
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/apt/sources.list.d/kubernetes.list` before running `apt-get update` and `apt-get upgrade`. This procedure is described in more detail in [Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
150+
{{< /note >}}
151+
152+
4. Update `apt` package index, then install kubectl:
153+
154+
```shell
155+
sudo apt-get update
156+
sudo apt-get install -y kubectl
157+
```
158+
159+
{{< note >}}
160+
In releases older than Debian 12 and Ubuntu 22.04, `/etc/apt/keyrings` does not exist by default, and can be created using `sudo mkdir -m 755 /etc/apt/keyrings`
161+
{{< /note >}}
162+
163+
{{% /tab %}}
164+
165+
{{% tab name="Red Hat-based distributions" %}}
166+
167+
1. Add the Kubernetes `yum` repository. If you want to use Kubernetes version
168+
different than {{< param "version" >}}, replace {{< param "version" >}} with
169+
the desired minor version in the command below.
170+
171+
```bash
172+
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
173+
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
174+
[kubernetes]
175+
name=Kubernetes
176+
baseurl=https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/rpm/
177+
enabled=1
178+
gpgcheck=1
179+
gpgkey=https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/rpm/repodata/repomd.xml.key
180+
EOF
181+
```
182+
183+
{{< note >}}
184+
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/yum.repos.d/kubernetes.repo` before running `yum update`. This procedure is described in more detail in [Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
185+
{{< /note >}}
186+
187+
2. Install kubectl using `yum`:
188+
189+
```bash
190+
sudo yum install -y kubectl
191+
```
192+
193+
{{% /tab %}}
194+
195+
{{% tab name="SUSE-based distributions" %}}
196+
197+
1. Add the Kubernetes `zypper` repository. If you want to use Kubernetes version
198+
different than {{< param "version" >}}, replace {{< param "version" >}} with
199+
the desired minor version in the command below.
200+
201+
```bash
202+
# This overwrites any existing configuration in /etc/zypp/repos.d/kubernetes.repo
203+
cat <<EOF | sudo tee /etc/zypp/repos.d/kubernetes.repo
204+
[kubernetes]
205+
name=Kubernetes
206+
baseurl=https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/rpm/
207+
enabled=1
208+
gpgcheck=1
209+
gpgkey=https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/rpm/repodata/repomd.xml.key
210+
EOF
211+
```
212+
213+
{{< note >}}
214+
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/zypp/repos.d/kubernetes.repo`
215+
before running `zypper update`. This procedure is described in more detail in
216+
[Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
217+
{{< /note >}}
218+
219+
2. Install kubectl using `zypper`:
220+
221+
```bash
222+
sudo zypper install -y kubectl
223+
```
224+
225+
{{% /tab %}}
226+
{{< /tabs >}}
227+
228+
### Install using other package management
229+
230+
{{< tabs name="other_kubectl_install" >}}
231+
{{% tab name="Snap" %}}
232+
If you are on Ubuntu or another Linux distribution that supports the
233+
[snap](https://snapcraft.io/docs/core/install) package manager, kubectl
234+
is available as a [snap](https://snapcraft.io/) application.
235+
236+
```shell
237+
snap install kubectl --classic
238+
kubectl version --client
239+
```
240+
241+
{{% /tab %}}
242+
243+
{{% tab name="Homebrew" %}}
244+
If you are on Linux and using [Homebrew](https://docs.brew.sh/Homebrew-on-Linux)
245+
package manager, kubectl is available for [installation](https://docs.brew.sh/Homebrew-on-Linux#install).
246+
247+
```shell
248+
brew install kubectl
249+
kubectl version --client
250+
```
251+
252+
{{% /tab %}}
253+
254+
{{< /tabs >}}
255+
256+
## Verify kubectl configuration
257+
258+
{{< include "included/verify-kubectl.md" >}}
259+
260+
## Optional kubectl configurations and plugins
261+
262+
### Enable shell autocompletion
263+
264+
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell,
265+
which can save you a lot of typing.
266+
267+
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
268+
269+
{{< tabs name="kubectl_autocompletion" >}}
270+
{{< tab name="Bash" include="included/optional-kubectl-configs-bash-linux.md" />}}
271+
{{< tab name="Fish" include="included/optional-kubectl-configs-fish.md" />}}
272+
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
273+
{{< /tabs >}}
274+
275+
### Install `kubectl convert` plugin
276+
277+
{{< include "included/kubectl-convert-overview.md" >}}
278+
279+
1. Download the latest release with the command:
280+
281+
{{< tabs name="download_convert_binary_linux" >}}
282+
{{< tab name="x86-64" codelang="bash" >}}
283+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
284+
{{< /tab >}}
285+
{{< tab name="ARM64" codelang="bash" >}}
286+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl-convert"
287+
{{< /tab >}}
288+
{{< /tabs >}}
289+
290+
1. Validate the binary (optional)
291+
292+
Download the kubectl-convert checksum file:
293+
294+
{{< tabs name="download_convert_checksum_linux" >}}
295+
{{< tab name="x86-64" codelang="bash" >}}
296+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert.sha256"
297+
{{< /tab >}}
298+
{{< tab name="ARM64" codelang="bash" >}}
299+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl-convert.sha256"
300+
{{< /tab >}}
301+
{{< /tabs >}}
302+
303+
Validate the kubectl-convert binary against the checksum file:
304+
305+
```bash
306+
echo "$(cat kubectl-convert.sha256) kubectl-convert" | sha256sum --check
307+
```
308+
309+
If valid, the output is:
310+
311+
```console
312+
kubectl-convert: OK
313+
```
314+
315+
If the check fails, `sha256` exits with nonzero status and prints output similar to:
316+
317+
```console
318+
kubectl-convert: FAILED
319+
sha256sum: WARNING: 1 computed checksum did NOT match
320+
```
321+
322+
{{< note >}}
323+
Download the same version of the binary and checksum.
324+
{{< /note >}}
325+
326+
1. Install kubectl-convert
327+
328+
```bash
329+
sudo install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
330+
```
331+
332+
1. Verify plugin is successfully installed
333+
334+
```shell
335+
kubectl convert --help
336+
```
337+
338+
If you do not see an error, it means the plugin is successfully installed.
339+
340+
1. After installing the plugin, clean up the installation files:
341+
342+
```bash
343+
rm kubectl-convert kubectl-convert.sha256
344+
```
345+
346+
## {{% heading "whatsnext" %}}
347+
348+
{{< include "included/kubectl-whats-next.md" >}}

0 commit comments

Comments
 (0)