Coder Social home page Coder Social logo

kubectl-azs's Introduction

azs Kubernetes CLI

The azs CLI is a utlity that can be used as a standalone binary or as a kubectl plugin to list Kubernetes objects by failure domain (commonly referred to as an Availability Zone). This utility requires a valid kubeconfig context and a given label on the cluster nodes to delineate the failure domain(s), and RBAC permissions to list Node resources. By default the failure-domain.kubernetes.io/zone and failure-domain.beta.kubernetes.io/zone labels are used.

This was an opportunity for me to start working with golang and is meant to be a simple example for building a kubectl plugin.

The utility is written in go and uses the cobra, and goreleaser projects.

Usage (Standalone)

The "azs" utility is a tool to list Kubernetes objects by Availability Zone. The utility can
be used standalone or as a "kubectl" plugin

Usage:
  azs [flags]
  azs [command]

Available Commands:
  help        Help about any command
  nodes       List Kubernetes nodes by AZ
  pods        List Kubernetes pods by AZ
  version     Prints the version of the "azs" utility

Flags:
      --context string      The name of the kubeconfig context to use
  -h, --help                help for azs
      --kubeconfig string   Kubernetes configuration file
  -l, --label string        The target label that defines the Availability Zone on nodes. The default value also includes
                            the beta version of the same label (default "failure-domain.kubernetes.io/zone")
  -n, --namespace string    The Namespace to use when listing Pods

Use "azs [command] --help" for more information about a command.

Use as a kubectl plugin

Copy binary into your path

$ cp ./azs /usr/local/bin/kubectl-azs

List Availability Zones using default label

$ kubectl azs                                                          
AZ
0
1
2

List Nodes and show Availability Zones using default label

$ kubectl azs nodes                                                        
NODE NAME                           AZ
aks-agentpool-94661123-vmss000000   0
aks-agentpool-94661123-vmss000001   1
aks-agentpool-94661123-vmss000002   2

List Nodes and show Availability Zones using custom label

$ kubectl azs nodes -l example.io/custom-az-label
NODE NAME                           AZ
aks-agentpool-94661123-vmss000000   az1
aks-agentpool-94661123-vmss000001   az2
aks-agentpool-94661123-vmss000002   az3

List Pods and show Availability Zones using default label

$ kubectl azs pods                                                        
NAME                                        NAMESPACE     NODE                                AZ
nginx                                       default       aks-agentpool-94661123-vmss000000   0
coredns-544d979687-dzsnh                    kube-system   aks-agentpool-94661123-vmss000000   0
coredns-544d979687-w4z55                    kube-system   aks-agentpool-94661123-vmss000002   2
coredns-autoscaler-6b69c49744-r4qd8         kube-system   aks-agentpool-94661123-vmss000002   2
dashboard-metrics-scraper-867cf6588-2pcmh   kube-system   aks-agentpool-94661123-vmss000002   2
kube-proxy-5fkl6                            kube-system   aks-agentpool-94661123-vmss000000   0
kube-proxy-jbdp6                            kube-system   aks-agentpool-94661123-vmss000002   2
kube-proxy-tm7cx                            kube-system   aks-agentpool-94661123-vmss000001   1
kubernetes-dashboard-7f7676f7b5-sz6dt       kube-system   aks-agentpool-94661123-vmss000002   2
metrics-server-6df44d5569-5czfg             kube-system   aks-agentpool-94661123-vmss000002   2
omsagent-4fjxj                              kube-system   aks-agentpool-94661123-vmss000000   0
omsagent-jm87x                              kube-system   aks-agentpool-94661123-vmss000001   1
omsagent-qbhz9                              kube-system   aks-agentpool-94661123-vmss000002   2
omsagent-rs-7bf46448f4-5z2v5                kube-system   aks-agentpool-94661123-vmss000001   1
tunnelfront-6446d9d9cc-fdrnv                kube-system   aks-agentpool-94661123-vmss000002   2

List Pods in a specific namespace and show Availability Zones using default label

$ kubectl azs pods -n default                                   
NAME                                        NAMESPACE     NODE                                AZ
nginx                                       default       aks-agentpool-94661123-vmss000000   0

Developers

Build a new release

  • Setup GitHub Personal Access Token

    $ export GITHUB_TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXX"
  • Edit the version in main.go

  • Tag new version and push

    $ git tag -a v0.0.1 -m "First release"
    $ git push origin v0.0.1
  • Build new binaries

    $ goreleaser --rm-dist

kubectl-azs's People

Contributors

phenixblue avatar

Stargazers

 avatar

Watchers

 avatar  avatar

kubectl-azs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.