Kubernetes Work on Windows » Historie » Zyklus 2
Peter Pfläging, 14.02.2023 13:19
| 1 | 1 | Peter Pfläging | # Kubernetes Work on Windows |
|---|---|---|---|
| 2 | |||
| 3 | This is a small guide for working with Kubernetes / Openshift / OKD on Windows. |
||
| 4 | |||
| 5 | It's not about installing the upper on Windows. The primary focus here is a DevOps / GitOps view managing one or many clusters from a Windows PC. |
||
| 6 | |||
| 7 | One of the main advantages is, that your typically not able to install everything on this Windows PC, because it's managed by your organisation / customer, ... |
||
| 8 | (if you can manage it by your own it's easier to install a Linux Desktop or use WSL2 on it!) |
||
| 9 | |||
| 10 | OK, let's begin. We want to work and comfortable edit environment on Windows. |
||
| 11 | |||
| 12 | ## Toolset |
||
| 13 | |||
| 14 | OK, what do we need: |
||
| 15 | |||
| 16 | - Editor |
||
| 17 | - Terminal Emulator |
||
| 18 | - Shell (unixoide Shell) |
||
| 19 | - ssh |
||
| 20 | - kubectl |
||
| 21 | - openshift CLI |
||
| 22 | - helm |
||
| 23 | - kubeseal (from Sealed Secrets) |
||
| 24 | |||
| 25 | ## GUI Programs |
||
| 26 | |||
| 27 | You need three Programs which install with GUI Installers (you can install all 3 without Admin privileges): |
||
| 28 | |||
| 29 | - Visual Studio Code <https://code.visualstudio.com/> |
||
| 30 | - Git Installer <https://git-scm.com/downloads> |
||
| 31 | - ConEmu as Terminal Emulation <https://conemu.github.io/> |
||
| 32 | |||
| 33 | Install all 3 with the default options for your environment. |
||
| 34 | |||
| 35 | ## Commandline programs |
||
| 36 | |||
| 37 | Add a directory `bin` to your homedirectory (for example `c:\Users\myusername\bin`). Add this to your Path: |
||
| 38 | |||
| 39 | - Windows Taskbar (right click) -> select "System" |
||
| 40 | - In the Settings window under "Related Settings" click "Advanced system settings" |
||
| 41 | - In the "Advanced" tab click "Environment variables" |
||
| 42 | - You have now to lists: "variables for myuser" & "system variables" |
||
| 43 | - double click "Path" in "variables for myuser" and add the path from above |
||
| 44 | |||
| 45 | Cool, ... |
||
| 46 | |||
| 47 | Now we install the following Windows binaries (`.EXE`) files in this directory: |
||
| 48 | |||
| 49 | - oc -> the OpenShift / OKD Command line (<https://github.com/okd-project/okd/releases/> use the newest `openshift-client-windows` package from here, unpack it and kick the `oc.exe` to the bin dir) |
||
| 50 | - kubectl -> the Kubernetes Command line (<https://dl.k8s.io/release/v1.26.0/bin/windows/amd64/kubectl.exe>) |
||
| 51 | - helm -> the package manager for Kubernetes (<https://github.com/helm/helm/releases>) |
||
| 52 | - kubeseal -> generate Sealed Secrets for Kubernetes and OpenShift (<https://github.com/bitnami-labs/sealed-secrets/releases>) |
||
| 53 | |||
| 54 | ## Customizings |
||
| 55 | |||
| 56 | ### Recommended Visual Studio Coder extensions |
||
| 57 | |||
| 58 | - Openshift Extension Pack (by Red Hat) |
||
| 59 | - Remote Development (by Microsoft) |
||
| 60 | - Git Extension Pack (by Don Jayamanne) |
||
| 61 | |||
| 62 | ### Shell environment |
||
| 63 | |||
| 64 | We use the git supplied bash and utilities for our unixoid environment (or linuxoid if you prefer it this way). |
||
| 65 | |||
| 66 | - *Visual Studio Code*: The terminal uses Powershell normally. You can switch to bash by: |
||
| 67 | - Open "Terminal -> New Terminal" |
||
| 68 | - click on the down-arrow on the right side of the Terminal |
||
| 69 | - Click "Choose standard profile" |
||
| 70 | - Click on "Git Bash" |
||
| 71 | - *ConEmu*: We want to use Bash as default terminal shell. |
||
| 72 | - Goto "Settings" (the menu comes in the menu button on the top right cornert (under the Windows close button)) |
||
| 73 | - In Settings: "Startup -> Specified named task: {Bash::Git bash} |
||
| 74 | - Save settings |
||
| 75 | |||
| 76 | At last wie want to show the actual kubernetes config in the command prompt (we use the famous [kube-ps1](https://github.com/jonmosco/kube-ps1) project for this): |
||
| 77 | |||
| 78 | - open a bash Window (either in VS-Code or ConEmu) |
||
| 79 | - download the `kube-ps1.sh` script from the [kube-ps1](https://github.com/jonmosco/kube-ps1) GitHub repo and place it in your `bin` directory: |
||
| 80 | `curl -Lo ~/bin/kube-ps1.sh https://raw.githubusercontent.com/jonmosco/kube-ps1/master/kube-ps1.sh` |
||
| 81 | - create an appropriate `.bash_profile` in your home directory with this: |
||
| 82 | |||
| 83 | ```shell |
||
| 84 | cat << EOF > ~/.bash_profile |
||
| 85 | source ~/bin/kube-ps1.sh |
||
| 86 | |||
| 87 | function get_cluster_short() { |
||
| 88 | echo "$1" | sed 's&.*/api-\([^-]*\)-.*:6443/\(.*\)&\1/\2&' |
||
| 89 | } |
||
| 90 | KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short |
||
| 91 | |||
| 92 | # PS1='[\u@\h \W $(kube_ps1)]\$ ' |
||
| 93 | PS1='$(kube_ps1) \w \$ ' |
||
| 94 | |||
| 95 | mkdir -p ~/lib/bash-completion |
||
| 96 | for comp in ~/lib/bash-completion/*.sh |
||
| 97 | do |
||
| 98 | . $comp |
||
| 99 | done |
||
| 100 | |||
| 101 | alias k=kubectl |
||
| 102 | alias more=less |
||
| 103 | EOF |
||
| 104 | ``` |
||
| 105 | - add the completion rules for commands: |
||
| 106 | |||
| 107 | ```shell |
||
| 108 | kubectl completion bash > ~/lib/bash-completion/kubectl.sh |
||
| 109 | oc completion bash > ~/lib/bash-completion/oc.sh |
||
| 110 | helm completion bash > ~/lib/bash-completion/helm.sh |
||
| 111 | ``` |