Skip to content

Commit 376a81e

Browse files
Fix file path
1 parent 8d1cef6 commit 376a81e

File tree

1 file changed

+305
-0
lines changed

1 file changed

+305
-0
lines changed
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
---
2+
reviewers:
3+
- mikedanese
4+
title: Instalar e configurar o kubectl no macOS
5+
content_type: task
6+
weight: 10
7+
---
8+
9+
## {{% heading "prerequisites" %}}
10+
11+
Você deve utilizar uma versão do kubectl que tenha pouca diferença da versão do
12+
seu cluster. Por exemplo, um cliente v{{< skew currentVersion >}} pode comunicar-se
13+
com control planes v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}},
14+
e v{{< skew currentVersionAddMinor 1 >}}.
15+
Usar a versão compatível e mais recente do kubectl pode evitar imprevistos ou problemas.
16+
17+
## Instalando o kubectl no macOS
18+
19+
Existem os seguintes métodos para instalar o kubectl no macOS:
20+
21+
- [Instalar kubectl no macOS](#instalar-kubectl-no-macos)
22+
- [Instalar o binário do kubectl com curl no macOS](#instalar-o-binario-do-kubectl-com-curl-no-macos)
23+
- [Instalar com Homebew no macOS](#instalar-com-homebrew-no-macos)
24+
- [Instalar com Macports no macOS](#instalar-com-macports-no-macos)
25+
- [Verificar ajustes do kubectl](#verificar-ajustes-do-kubectl)
26+
- [Plugins e ajustes opcionais do kubectl](#plugins-e-ajustes-opcionais-do-kubectl)
27+
- [Habilitar autocomplete no shell](#habilitar-autocomplete-no-shell)
28+
- [Instalar `kubectl convert` plugin](#instalar-kubectl-convert-plugin)
29+
30+
### Instalar o binário do kubectl com o curl no macOS
31+
32+
1. Baixe a última versão:
33+
34+
{{< tabs name="download_binary_macos" >}}
35+
{{< tab name="Intel" codelang="bash" >}}
36+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
37+
{{< /tab >}}
38+
{{< tab name="Apple Silicon" codelang="bash" >}}
39+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"
40+
{{< /tab >}}
41+
{{< /tabs >}}
42+
43+
{{< note >}}
44+
Para baixar uma versão específica, substitua `$(curl -L -s https://dl.k8s.io/release/stable.txt)`
45+
parte do comando com a versão específica da versão.
46+
47+
Por exemplo, para baixar a versão {{< skew currentPatchVersion >}} no Intel macOS, digite:
48+
49+
```bash
50+
curl -LO "https://dl.k8s.io/release/v{{< skew currentPatchVersion >}}/bin/darwin/amd64/kubectl"
51+
```
52+
53+
E para macOS no Apple Silicon, digite:
54+
55+
```bash
56+
curl -LO "https://dl.k8s.io/release/v{{< skew currentPatchVersion >}}/bin/darwin/arm64/kubectl"
57+
```
58+
59+
{{< /note >}}
60+
61+
1. Validando o binário (opcional).
62+
63+
Baixe o arquivo de checksum do kubectl:
64+
65+
{{< tabs name="download_checksum_macos" >}}
66+
{{< tab name="Intel" codelang="bash" >}}
67+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256"
68+
{{< /tab >}}
69+
{{< tab name="Apple Silicon" codelang="bash" >}}
70+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256"
71+
{{< /tab >}}
72+
{{< /tabs >}}
73+
74+
Validando o binário do kubectl com o arquivo de checksum:
75+
76+
```bash
77+
echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check
78+
```
79+
80+
Se for válido, a saída será:
81+
82+
```console
83+
kubectl: OK
84+
```
85+
86+
Se a houver falha na validação, `shasum` ele retornará uma saída diferente de zero semelhante a:
87+
88+
```console
89+
kubectl: FAILED
90+
shasum: WARNING: 1 computed checksum did NOT match
91+
```
92+
93+
{{< note >}}
94+
Baixe a mesma versão do binário e do checksum.
95+
{{< /note >}}
96+
97+
1. Tornando o binário do kubectl executável.
98+
99+
```bash
100+
chmod +x ./kubectl
101+
```
102+
103+
1. Movendo o binário do kubectl para um diretório do seu sistema `PATH`.
104+
105+
```bash
106+
sudo mv ./kubectl /usr/local/bin/kubectl
107+
sudo chown root: /usr/local/bin/kubectl
108+
```
109+
110+
{{< note >}}
111+
Tenha certeza que `/usr/local/bin` está configurado na sua variável de ambiente PATH.
112+
{{< /note >}}
113+
114+
1. Teste para validar que a versão instalada está atualizada:
115+
116+
```bash
117+
kubectl version --client
118+
```
119+
120+
Ou se preferir, use o seguinte comando para uma visão mais detalhada sobre a versão do Kubernetes:
121+
122+
```cmd
123+
kubectl version --client --output=yaml
124+
```
125+
126+
1. Depois de instalar e validar o kubectl, delete o arquivo de checksum:
127+
128+
```bash
129+
rm kubectl.sha256
130+
```
131+
132+
### Instalar com Homebrew no macOS
133+
134+
Se você está no macOS e usando o gerenciador de pacote [Homebrew](https://brew.sh/),
135+
você pode instalar o kubectl usando o Homebrew.
136+
137+
1. Execute o comando de instalação:
138+
139+
```bash
140+
brew install kubectl
141+
```
142+
143+
ou
144+
145+
```bash
146+
brew install kubernetes-cli
147+
```
148+
149+
1. Teste para validar se a versão instalada está atualizada:
150+
151+
```bash
152+
kubectl version --client
153+
```
154+
155+
### Instalar com Macports no macOS
156+
157+
Se você está no macOS, usando o gerenciador de pacotes [Macports](https://macports.org/),
158+
você pode instalar o kubectl utilizando o Macports.
159+
160+
1. Execute o comando de instalação:
161+
162+
```bash
163+
sudo port selfupdate
164+
sudo port install kubectl
165+
```
166+
167+
1. Teste para validar se a versão instalada está atualizada:
168+
169+
```bash
170+
kubectl version --client
171+
```
172+
173+
## Verificar ajustes do kubectl
174+
175+
{{< include "included/verify-kubectl.md" >}}
176+
177+
## Plugins e ajustes opcionais do kubectl
178+
179+
### Habilitar autocomplete no shell
180+
181+
O kubectl fornece suporte para auto-complete para Bash, Zsh, Fish, e PowerShell
182+
o que pode fazer com que você digite menos.
183+
184+
Abaixo seguem os procedimentos para configurar o auto-complete para Bash, Fish, and Zsh.
185+
186+
{{< tabs name="kubectl_autocompletion" >}}
187+
{{< tab name="Bash" include="included/optional-kubectl-configs-bash-mac.md" />}}
188+
{{< tab name="Fish" include="included/optional-kubectl-configs-fish.md" />}}
189+
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
190+
{{< /tabs >}}
191+
192+
### Instalar `kubectl convert` plugin
193+
194+
{{< include "included/kubectl-convert-overview.md" >}}
195+
196+
1. Baixe a última versão com o comando:
197+
198+
{{< tabs name="download_convert_binary_macos" >}}
199+
{{< tab name="Intel" codelang="bash" >}}
200+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert"
201+
{{< /tab >}}
202+
{{< tab name="Apple Silicon" codelang="bash" >}}
203+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert"
204+
{{< /tab >}}
205+
{{< /tabs >}}
206+
207+
1. Valide o binário (opcional).
208+
209+
Baixe o arquivo de checksum do kubectl-convert:
210+
211+
{{< tabs name="download_convert_checksum_macos" >}}
212+
{{< tab name="Intel" codelang="bash" >}}
213+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert.sha256"
214+
{{< /tab >}}
215+
{{< tab name="Apple Silicon" codelang="bash" >}}
216+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert.sha256"
217+
{{< /tab >}}
218+
{{< /tabs >}}
219+
220+
Valide o binário do kubectl-convert com o checksum:
221+
222+
```bash
223+
echo "$(cat kubectl-convert.sha256) kubectl-convert" | shasum -a 256 --check
224+
```
225+
226+
Se for válido, a saída será:
227+
228+
```console
229+
kubectl-convert: OK
230+
```
231+
232+
Se o teste falhar, `shasum` irá retornar um status com número diferente de zero, e uma saída parecida como abaixo:
233+
234+
```console
235+
kubectl-convert: FAILED
236+
shasum: WARNING: 1 computed checksum did NOT match
237+
```
238+
239+
{{< note >}}
240+
Baixe a mesma versão do binário e do checksum.
241+
{{< /note >}}
242+
243+
1. Torne o binário do kubectl-convert um executável.
244+
245+
```bash
246+
chmod +x ./kubectl-convert
247+
```
248+
249+
1. Mova o binário do kubectl-convert para o `PATH` do sistema.
250+
251+
```bash
252+
sudo mv ./kubectl-convert /usr/local/bin/kubectl-convert
253+
sudo chown root: /usr/local/bin/kubectl-convert
254+
```
255+
256+
{{< note >}}
257+
Tenha certeza de que `/usr/local/bin` está no PATH em suas configurações de variáveis ambiente.
258+
{{< /note >}}
259+
260+
1. Verifique se o plugin foi instalado com sucesso.
261+
262+
```shell
263+
kubectl convert --help
264+
```
265+
266+
Se você não encontrar nenhum erro, isso quer dizer que o plugin foi instalado com sucesso.
267+
268+
1. Após instalar o plugin, limpe os arquivos de instalação:
269+
270+
```bash
271+
rm kubectl-convert kubectl-convert.sha256
272+
```
273+
274+
### Desinstalar kubectl no macOS
275+
276+
Dependendo da forma que você instalou o `kubectl`, use um dos métodos abaixo.
277+
278+
### Desinstalar o kubectl usando a linha de comando
279+
280+
1. Localize o binário do `kubectl` no seu sistema:
281+
282+
```bash
283+
which kubectl
284+
```
285+
286+
1. Remova o binário `kubectl`:
287+
288+
```bash
289+
sudo rm <path>
290+
```
291+
Substitua `<path>` com o PATH do binário `kubectl` conforme os passos anteriores. Por exemplo, `sudo rm /usr/local/bin/kubectl`.
292+
293+
### Desinstalar o kubectl usando o homebrew
294+
295+
Se você instalou o `kubectl` utilizando Homebrew, execute o comando a seguir:
296+
297+
```bash
298+
brew remove kubectl
299+
```
300+
301+
## {{% heading "whatsnext" %}}
302+
303+
{{< include "included/kubectl-whats-next.md" >}}
304+
305+

0 commit comments

Comments
 (0)