Box

Allgemein

Profil

Kubernetes Work on Windows » Historie » Zyklus 1

Peter Pfläging, 14.02.2023 13:19

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