Scenario:
Building upon my previous blog post Managing Azure with Az CLI and Windows Subsystem for Linux, I want to demonstrate examples and techniques in managing a Kubernetes cluster on Azure Kubernetes Service (AKS) in a bash shell using Windows Subsystem for Linux.
As a mainstream Microsoft platform developer and engineer for most of my career, I use many script examples that work in PowerShell and windows cmd terminal. As I have being doing more projects with open source projects on Linux and Kubernetes, I come across more script examples and command line tools that work exclusively or better in a Linux shell. Such scripts just can’t be done or ported easily to a windows console or PowerShell script.
Therefore, using WSL on my Windows 10 machine, I am comfortably able to be sufficient Linux oriented systems engineer and developer.

In managing Kubernetes cluster in Azure Kubernetes Service, a few popular Linux tools and utilities come up in scripting examples I find in online resources. And scripts and examples that have these tools, you can run in your Linux environment via WSL. These popular tools are as follows.
grep
A utility for searching plain-text data sets for lines that match a regular expression.
Example:
Filter on output lines that contain ‘Ready=True’
kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"
I find that grep is widely used with kubectl commands and scripts.
vim text editor
A highly configurable text editor for efficiently creating and changing any kind of text.
Useful for editing files when SSH into a Kubernetes container to change files. An example would be to
troubleshoot issues by changing configuration files.
Bash scripting language
A programming language to run commands and have standard programming logic. A bash shell has a file extension of .sh and its file has its first line as #!/bin/bash. A prime example is to have a shell script with a of az cli and linux commands to create and configure an azure Kubernetes cluster. As well as automate other devops processes.
curl
A tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP).
Example:curl http://$(kubectl get service sample-app -o jsonpath='{ .spec.clusterIP }')/metrics
This tool is used very often. I can’t find a comparable command in PowerShell, so I’m often switching to a Linux environment.
A stream editor utility that parses and transforms text using regular expressions. It can be used for filtering.
Example:
Replace ‘hello’ with world’echo 'hello world ' | sed 's/hello/world/'
output: “world world”
Kubernetes Example:
# Update a single-container pod’s image version (tag) to v4kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
Reference: https://kubernetes.io/docs/reference/kubectl/cheatsheet/#updating-resources
This sed tool, in my opinion is that it is hard to understand and use from scratch, but on occasion there are script examples that are useful.
A utility the executes a program periodically. It can demonstrate as if it were a near real time live dashboard
A Kubernetes example:
Monitor cpu and memory usage of nodes and pods
watch -n 1 kubectl top nodes
watch -n 1 kubectl top pods
output:

For my shell scripts for Kubernetes that include these tools you can find them at https://github.com/RoyKimYYZ/linux-scripts/blob/master/manage-kubernetes.sh
Concluding Remarks
In the year 2020 and beyond, I find that working only on the Windows platform may not make for a vibrant and versatile tech career. As Microsoft is embracing Linux and cross platform such as PowerShell and .NET core and Linux and Kubernetes in Azure, I am compelled to keep a strong foundation with Linux skills. Yet at the same time, you don’t need to be an expert. Nonetheless, I encourage the traditional Microsoft developers and engineers to embrace Linux and Open Source Software.
Reblogged this on El Bruno.