|
| 1 | +--- |
| 2 | +title: Kubectl installieren und konfigurieren auf macOS |
| 3 | +content_type: task |
| 4 | +weight: 10 |
| 5 | +card: |
| 6 | + name: tasks |
| 7 | + weight: 20 |
| 8 | + title: Kubectl auf macOS installieren |
| 9 | +--- |
| 10 | + |
| 11 | +## {{% heading "prerequisites" %}} |
| 12 | + |
| 13 | +Sie müssen eine kubectl-Version verwenden, welche nicht mehr als eine Minor-Version Unterschied zu ihrem Cluster aufweist. Zum Beispiel: eine Client-Version v{{< skew currentVersion >}} kann mit folgenden versionen kommunizieren v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}}, und v{{< skew currentVersionAddMinor 1 >}}. |
| 14 | +Die Verwendung der neuesten kompatiblen Version von kubectl hilft, unvorhergesehene Probleme zu vermeiden. |
| 15 | + |
| 16 | +## Kubectl auf macOS installieren |
| 17 | + |
| 18 | +Um kubectl auf macOS zu installieren, gibt es die folgenden Möglichkeiten: |
| 19 | + |
| 20 | +- [{{% heading "prerequisites" %}}](#-heading-prerequisites-) |
| 21 | +- [Kubectl auf macOS installieren](#kubectl-auf-macos-installieren) |
| 22 | + - [Kubectl Binary mit curl auf macOS installieren](#kubectl-binary-mit-curl-auf-macos-installieren) |
| 23 | + - [Mit Homebrew auf macOS installieren](#mit-homebrew-auf-macos-installieren) |
| 24 | + - [Install with Macports on macOS](#install-with-macports-on-macos) |
| 25 | +- [Kubectl Konfiguration verifizieren](#kubectl-konfiguration-verifizieren) |
| 26 | +- [Optionale kubectl Konfigurationen und Plugins](#optionale-kubectl-konfigurationen-und-plugins) |
| 27 | + - [Shell Autovervollständigung einbinden](#shell-autovervollständigung-einbinden) |
| 28 | + - [`kubectl convert` Plugin intallieren](#kubectl-convert-plugin-intallieren) |
| 29 | +- [{{% heading "whatsnext" %}}](#-heading-whatsnext-) |
| 30 | + |
| 31 | +### Kubectl Binary mit curl auf macOS installieren |
| 32 | + |
| 33 | +1. Das aktuellste Release downloaden: |
| 34 | + |
| 35 | + {{< tabs name="download_binary_macos" >}} |
| 36 | + {{< tab name="Intel" codelang="bash" >}} |
| 37 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" |
| 38 | + {{< /tab >}} |
| 39 | + {{< tab name="Apple Silicon" codelang="bash" >}} |
| 40 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl" |
| 41 | + {{< /tab >}} |
| 42 | + {{< /tabs >}} |
| 43 | + |
| 44 | + {{< note >}} |
| 45 | + Um eine spezifische Version herunterzuladen, ersetzen sie `$(curl -L -s https://dl.k8s.io/release/stable.txt)` mit der spezifischen Version |
| 46 | + |
| 47 | + Um zum Beispiel Version {{< param "fullversion" >}} auf Intel macOS herunterzuladen: |
| 48 | + |
| 49 | + ```bash |
| 50 | + curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl" |
| 51 | + ``` |
| 52 | + |
| 53 | + Für macOS auf Apple Silicon (z.B. M1/M2): |
| 54 | + |
| 55 | + ```bash |
| 56 | + curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/arm64/kubectl" |
| 57 | + ``` |
| 58 | + |
| 59 | + {{< /note >}} |
| 60 | + |
| 61 | +2. Binary validieren (optional) |
| 62 | + |
| 63 | + Downloaden die die kubectl Checksum-Datei: |
| 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 | + Validieren Sie die Kubectl Binary mit der Checksum-Datei: |
| 75 | + |
| 76 | + ```bash |
| 77 | + echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check |
| 78 | + ``` |
| 79 | + |
| 80 | + Wenn Valide, dann sieht die Ausgabe wie folgt aus: |
| 81 | + |
| 82 | + ```console |
| 83 | + kubectl: OK |
| 84 | + ``` |
| 85 | + |
| 86 | + Falls die Validierung fehlschlägt, beendet sich `shasum` mit einem "nonzero"-Status und gibt einen Fehler aus, welcher so aussehen könnte: |
| 87 | + |
| 88 | + ```bash |
| 89 | + kubectl: FAILED |
| 90 | + shasum: WARNING: 1 computed checksum did NOT match |
| 91 | + ``` |
| 92 | + |
| 93 | + {{< note >}} |
| 94 | + Laden sie von der Binary und Checksum-Datei immer die selben Versionen herunter. |
| 95 | + {{< /note >}} |
| 96 | + |
| 97 | +3. Kubectl Binary ausführbar machen. |
| 98 | + |
| 99 | + ```bash |
| 100 | + chmod +x ./kubectl |
| 101 | + ``` |
| 102 | + |
| 103 | +4. Kubectl Binary zu einem Ordner in ihrem `PATH` verschieben. |
| 104 | + |
| 105 | + ```bash |
| 106 | + sudo mv ./kubectl /usr/local/bin/kubectl |
| 107 | + sudo chown root: /usr/local/bin/kubectl |
| 108 | + ``` |
| 109 | + |
| 110 | + {{< note >}} |
| 111 | + Stellen Sie sicher, dass `/usr/local/bin` in ihrer PATH Umgebungsvariable gesetzt ist. |
| 112 | + {{< /note >}} |
| 113 | + |
| 114 | +5. Prüfen ob die installierte Version die aktuellste Version ist: |
| 115 | + |
| 116 | + ```bash |
| 117 | + kubectl version --client |
| 118 | + ``` |
| 119 | + |
| 120 | + {{< note >}} |
| 121 | + Der oben stehende Befehl wirft folgende Warnung: |
| 122 | + |
| 123 | + ``` |
| 124 | + WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. |
| 125 | + ``` |
| 126 | + |
| 127 | + Sie können diese Warnung ignorieren. Sie prüfen lediglich die `kubectl` Version welche sie installiert haben. |
| 128 | + |
| 129 | + {{< /note >}} |
| 130 | + |
| 131 | + Oder benutzten sie diesen Befehl für einer detailliertere Ansicht: |
| 132 | + |
| 133 | + ```cmd |
| 134 | + kubectl version --client --output=yaml |
| 135 | + ``` |
| 136 | + |
| 137 | +6. Nach Installation des Plugins, die installations Dateien aufräumen: |
| 138 | + |
| 139 | + ```bash |
| 140 | + rm kubectl kubectl.sha256 |
| 141 | + ``` |
| 142 | + |
| 143 | +### Mit Homebrew auf macOS installieren |
| 144 | + |
| 145 | +Wenn Sie macOS und [Homebrew](https://brew.sh/) als Paketmanager benutzen, |
| 146 | +können Sie kubectl über diesen installieren. |
| 147 | + |
| 148 | +1. Führen Sie den Installationsbefehl aus: |
| 149 | + |
| 150 | + ```bash |
| 151 | + brew install kubectl |
| 152 | + ``` |
| 153 | + |
| 154 | + oder |
| 155 | + |
| 156 | + ```bash |
| 157 | + brew install kubernetes-cli |
| 158 | + ``` |
| 159 | + |
| 160 | +2. Prüfen ob die installierte Version die aktuellste Version ist: |
| 161 | + |
| 162 | + ```bash |
| 163 | + kubectl version --client |
| 164 | + ``` |
| 165 | + |
| 166 | +### Install with Macports on macOS |
| 167 | + |
| 168 | +Wenn Sie macOS und [Macports](https://macports.org/) als Paketmanager benutzen, können Sie kubectl über diesen installieren. |
| 169 | + |
| 170 | +1. Führen Sie den Installationsbefehl aus: |
| 171 | + |
| 172 | + ```bash |
| 173 | + sudo port selfupdate |
| 174 | + sudo port install kubectl |
| 175 | + ``` |
| 176 | + |
| 177 | +1. Prüfen ob die installierte Version die aktuellste Version ist: |
| 178 | + |
| 179 | + ```bash |
| 180 | + kubectl version --client |
| 181 | + ``` |
| 182 | + |
| 183 | +## Kubectl Konfiguration verifizieren |
| 184 | + |
| 185 | +{{< include "included/verify-kubectl.md" >}} |
| 186 | + |
| 187 | +## Optionale kubectl Konfigurationen und Plugins |
| 188 | + |
| 189 | +### Shell Autovervollständigung einbinden |
| 190 | + |
| 191 | +kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell |
| 192 | +which can save you a lot of typing. |
| 193 | + |
| 194 | +Below are the procedures to set up autocompletion for Bash, Fish, and Zsh. |
| 195 | + |
| 196 | +{{< tabs name="kubectl_autocompletion" >}} |
| 197 | +{{< tab name="Bash" include="included/optional-kubectl-configs-bash-mac.md" />}} |
| 198 | +{{< tab name="Fish" include="included/optional-kubectl-configs-fish.md" />}} |
| 199 | +{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}} |
| 200 | +{{< /tabs >}} |
| 201 | + |
| 202 | +### `kubectl convert` Plugin intallieren |
| 203 | + |
| 204 | +{{< include "included/kubectl-convert-overview.md" >}} |
| 205 | + |
| 206 | +1. Download the latest release with the command: |
| 207 | + |
| 208 | + {{< tabs name="download_convert_binary_macos" >}} |
| 209 | + {{< tab name="Intel" codelang="bash" >}} |
| 210 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert" |
| 211 | + {{< /tab >}} |
| 212 | + {{< tab name="Apple Silicon" codelang="bash" >}} |
| 213 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert" |
| 214 | + {{< /tab >}} |
| 215 | + {{< /tabs >}} |
| 216 | + |
| 217 | +1. Validate the binary (optional) |
| 218 | + |
| 219 | + Download the kubectl-convert checksum file: |
| 220 | + |
| 221 | + {{< tabs name="download_convert_checksum_macos" >}} |
| 222 | + {{< tab name="Intel" codelang="bash" >}} |
| 223 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert.sha256" |
| 224 | + {{< /tab >}} |
| 225 | + {{< tab name="Apple Silicon" codelang="bash" >}} |
| 226 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert.sha256" |
| 227 | + {{< /tab >}} |
| 228 | + {{< /tabs >}} |
| 229 | + |
| 230 | + Validate the kubectl-convert binary against the checksum file: |
| 231 | + |
| 232 | + ```bash |
| 233 | + echo "$(cat kubectl-convert.sha256) kubectl-convert" | shasum -a 256 --check |
| 234 | + ``` |
| 235 | + |
| 236 | + If valid, the output is: |
| 237 | + |
| 238 | + ```console |
| 239 | + kubectl-convert: OK |
| 240 | + ``` |
| 241 | + |
| 242 | + If the check fails, `shasum` exits with nonzero status and prints output similar to: |
| 243 | + |
| 244 | + ```bash |
| 245 | + kubectl-convert: FAILED |
| 246 | + shasum: WARNING: 1 computed checksum did NOT match |
| 247 | + ``` |
| 248 | + |
| 249 | + {{< note >}} |
| 250 | + Download the same version of the binary and checksum. |
| 251 | + {{< /note >}} |
| 252 | + |
| 253 | +1. Make kubectl-convert binary executable |
| 254 | + |
| 255 | + ```bash |
| 256 | + chmod +x ./kubectl-convert |
| 257 | + ``` |
| 258 | + |
| 259 | +1. Move the kubectl-convert binary to a file location on your system `PATH`. |
| 260 | + |
| 261 | + ```bash |
| 262 | + sudo mv ./kubectl-convert /usr/local/bin/kubectl-convert |
| 263 | + sudo chown root: /usr/local/bin/kubectl-convert |
| 264 | + ``` |
| 265 | + |
| 266 | + {{< note >}} |
| 267 | + Make sure `/usr/local/bin` is in your PATH environment variable. |
| 268 | + {{< /note >}} |
| 269 | + |
| 270 | +1. Verify plugin is successfully installed |
| 271 | + |
| 272 | + ```shell |
| 273 | + kubectl convert --help |
| 274 | + ``` |
| 275 | + |
| 276 | + If you do not see an error, it means the plugin is successfully installed. |
| 277 | + |
| 278 | +1. After installing the plugin, clean up the installation files: |
| 279 | + |
| 280 | + ```bash |
| 281 | + rm kubectl-convert kubectl-convert.sha256 |
| 282 | + ``` |
| 283 | + |
| 284 | +## {{% heading "whatsnext" %}} |
| 285 | + |
| 286 | +{{< include "included/kubectl-whats-next.md" >}} |
0 commit comments