Coder Social home page Coder Social logo

sunny-b / kubectl-koptica Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahmetb/kubectl-foreach

0.0 1.0 0.0 79 KB

Run kubectl commands in all/some contexts in parallel (similar to GNU xargs+parallel)

License: Apache License 2.0

Go 100.00%

kubectl-koptica's Introduction

kubectl koptica

Run a kubectl command in one or more contexts (clusters) in parallel (similar to GNU parallel/xargs).

Usage

    kubectl koptica [OPTIONS] [PATTERN]... -- [KUBECTL_ARGS...]

Patterns can be used to match context names from kubeconfig:
      (empty): matches all contexts
         NAME: matches context with exact name
    /PATTERN/: matches context with regular expression
        ^NAME: remove context with exact name from the matched results
   ^/PATTERN/: remove contexts matching the regular expression from the results
    
Options:
    -c=NUM     Limit parallel executions (default: 0, unlimited)
    -I=VAL     Replace VAL occurring in KUBECTL_ARGS with context name
    -q         Suppress output
    -y         Disable and accept confirmation prompts ($KUBECTL_KOPTICA_DISABLE_PROMPTS) 
    -l         Display kube contexts matching the query and exit
    -h/--help  Print help

Demo

Query a pod by label in minikube and *-prod* contexts:

$ kubectl koptica /-prod/ minikube -- get pods -n kube-system --selector compute.twitter.com/app=coredns --no-headers

     eu-prod | coredns-59bd9867bb-6rbx7   2/2     Running   0          78d
     eu-prod | coredns-59bd9867bb-9xczh   2/2     Running   0          78d
     eu-prod | coredns-59bd9867bb-fvn6t   2/2     Running   0          78d
    minikube | No resources found in kube-system namespace.
 useast-prod | coredns-6fd4bd9db4-7w9wv   2/2     Running   0          78d
 useast-prod | coredns-6fd4bd9db4-9pk8n   2/2     Running   0          78d
 useast-prod | coredns-6fd4bd9db4-xphr4   2/2     Running   0          78d
 uswest-prod | coredns-6f987df9bc-6fgc2   2/2     Running   0          78d
 uswest-prod | coredns-6f987df9bc-9gxvt   2/2     Running   0          78d
 uswest-prod | coredns-6f987df9bc-d88jk   2/2     Running   0          78d

Examples

Match to contexts by name: Run a command ("kubectl version") on contexts c1, c2 and c3:

kubectl koptica c1 c2 c3 -- version

Match to contexts by pattern: Run a command on contexts starting with gke (regular expression syntax):

kubectl koptica /^gke/ -- get pods

Match all contexts: empty context matches all contexts.

kubectl koptica -- version

Excluding contexts: Use the matching syntaxes with a ^ prefix to use them for exclusion. If no matching contexts are specified.

e.g. match all contexts except c1 and except those ending with prod (single quotes for escaping $ in the shell):

kubectl koptica ^c1 ^/prod'$'/ -- version

Using with kubectl plugins: Customize how context name is passed to the command (useful for kubectl plugins as --context must be specified after plugin name).

In this example, _ is replaced with the context name when calling "kubectl my_plugin".

kubectl koptica -I _ -- my_plugin -ctx=_

Limit parallelization: Only run 3 commands at a time:

kubectl koptica -c 3 /^gke-/

Remarks

Do not use this tool programmatically yet:

This tool is not intended for deploying workloads to clusters, or using programmatically. Therefore, it does not provide a structured output format or ordered printing that is meant to be parsed by or piped to other programs (maybe except for grep).

kubectl-koptica's People

Contributors

ahmetb avatar pehlicd avatar rajatjindal avatar semihbkgr avatar

Watchers

 avatar

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.