Box

Allgemein

Profil

Aktionen

Kubernetes Work on Windows

This is a small guide for working with Kubernetes / Openshift / OKD on Windows.

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.

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, ...
(if you can manage it by your own it's easier to install a Linux Desktop or use WSL2 on it!)

OK, let's begin. We want to work and comfortable edit environment on Windows.

Toolset

OK, what do we need:

  • Editor
  • Terminal Emulator
  • Shell (unixoide Shell)
  • ssh
  • kubectl
  • openshift CLI
  • helm
  • kubeseal (from Sealed Secrets)

GUI Programs

You need three Programs which install with GUI Installers (you can install all 3 without Admin privileges):

Install all 3 with the default options for your environment.

Commandline programs

Add a directory bin to your homedirectory (for example c:\Users\myusername\bin). Add this to your Path:

  • Windows Taskbar (right click) -> select "System"
  • In the Settings window under "Related Settings" click "Advanced system settings"
  • In the "Advanced" tab click "Environment variables"
  • You have now to lists: "variables for myuser" & "system variables"
  • double click "Path" in "variables for myuser" and add the path from above

Cool, ...

Now we install the following Windows binaries (.EXE) files in this directory:

Customizings

Recommended Visual Studio Coder extensions

  • Openshift Extension Pack (by Red Hat)
  • Remote Development (by Microsoft)
  • Git Extension Pack (by Don Jayamanne)

Shell environment

We use the git supplied bash and utilities for our unixoid environment (or linuxoid if you prefer it this way).

  • Visual Studio Code: The terminal uses Powershell normally. You can switch to bash by:
    • Open "Terminal -> New Terminal"
    • click on the down-arrow on the right side of the Terminal
    • Click "Choose standard profile"
    • Click on "Git Bash"
  • ConEmu: We want to use Bash as default terminal shell.
    • Goto "Settings" (the menu comes in the menu button on the top right cornert (under the Windows close button))
    • In Settings: "Startup -> Specified named task: {Bash::Git bash}
    • Save settings

At last wie want to show the actual kubernetes config in the command prompt (we use the famous kube-ps1 project for this):

  • open a bash Window (either in VS-Code or ConEmu)

  • download the kube-ps1.sh script from the kube-ps1 GitHub repo and place it in your bin directory:
    curl -Lo ~/bin/kube-ps1.sh https://raw.githubusercontent.com/jonmosco/kube-ps1/master/kube-ps1.sh

  • create an appropriate .bash_profile in your home directory with this:

    cat << EOF > ~/.bash_profile
    source ~/bin/kube-ps1.sh
    
    function get_cluster_short() {
      echo "$1" | sed 's&.*/api-\([^-]*\)-.*:6443/\(.*\)&\1/\2&'
    }
    KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short
    
    # PS1='[\u@\h \W $(kube_ps1)]\$ '
    PS1='$(kube_ps1) \w \$ '
    
    mkdir -p ~/lib/bash-completion
    for comp in ~/lib/bash-completion/*.sh
    do
      . $comp
    done
    
    alias k=kubectl
    alias more=less
    EOF
    
  • add the completion rules for commands:

    kubectl completion bash > ~/lib/bash-completion/kubectl.sh
    oc completion bash > ~/lib/bash-completion/oc.sh
    helm completion bash > ~/lib/bash-completion/helm.sh
    

Von Peter Pfläging vor etwa 2 Jahren aktualisiert · 2 Revisionen