Kubectl Plugin

Kruise-tools provides commandline tools for kruise features, such as kubectl-kruise, which is a standard plugin of kubectl.

Install

Install via Krew

  1. Krew itself is a kubectl plugin that is installed and updated via Krew (yes, Krew self-hosts). First, install krew.

  2. Run kubectl krew install kruise to install kruise plugin via Krew.

  3. Then you can use it with kubectl-kruise or kubectl kruise.

  1. $ kubectl-kruise --help
  2. # or
  3. $ kubectl kruise --help

Install manually

  1. You can simply download the binary from the releases page. Currently linux, darwin(OS X), windows with x86_64 and arm64 are provided. If you are using some other systems or architectures, you have to download the kruise-tools and execute make build to build the binary.

  2. Extract and move it to system PATH.

  1. $ tar xvf kubectl-kruise-darwin-amd64.tar.gz
  2. $ mv darwin-amd64/kubectl-kruise /usr/local/bin/
  1. Then you can use it with kubectl-kruise or kubectl kruise.
  1. $ kubectl-kruise --help
  2. # or
  3. $ kubectl kruise --help

Upgrade

Upgrade via Krew

Run kubectl krew upgrade kruise to upgrade kruise plugin via Krew.

Upgrade manually

Same to install plugin manually.

Usage

expose

Take a workload(e.g. deployment, cloneset), service or pod and expose it as a new Kubernetes Service.

  1. $ kubectl kruise expose cloneset nginx --port=80 --target-port=8000

scale

Set a new size for a Deployment, ReplicaSet, CloneSet, or Advanced StatefulSet.

  1. $ kubectl kruise scale --replicas=3 cloneset nginx

It equals to kubectl scale --replicas=3 cloneset nginx.

rollout

Available commands: history, pause, restart, resume, status, undo, approve.

  1. $ kubectl kruise rollout undo cloneset/nginx
  2. # built-in statefulsets
  3. $ kubectl kruise rollout status statefulsets/sts1
  4. # kruise statefulsets
  5. $ kubectl kruise rollout status statefulsets.apps.kruise.io/sts2
  6. # approve a kruise rollout resource named "rollout-demo" in "ns-demo" namespace
  7. $ kubectl-kruise rollout approve rollout-demo -n ns-demo

set

Available commands: env, image, resources, selector, serviceaccount, subject.

  1. $ kubectl kruise set env cloneset/nginx STORAGE_DIR=/local
  2. $ kubectl kruise set image cloneset/nginx busybox=busybox nginx=nginx:1.9.1

migrate

Currently it supports migrate from Deployment to CloneSet.

  1. # Create an empty CloneSet from an existing Deployment.
  2. $ kubectl kruise migrate CloneSet --from Deployment -n default --dst-name deployment-name --create
  3. # Create a same replicas CloneSet from an existing Deployment.
  4. $ kubectl kruise migrate CloneSet --from Deployment -n default --dst-name deployment-name --create --copy
  5. # Migrate replicas from an existing Deployment to an existing CloneSet.
  6. $ kubectl-kruise migrate CloneSet --from Deployment -n default --src-name cloneset-name --dst-name deployment-name --replicas 10 --max-surge=2

exec

Support switch to raw terminal mode, sends stdin to ‘bash’ in working sidecar container from cloneset myclone or pod and sends stdout/stderr from ‘bash’ back to the client

  1. # exec sidecar in pod
  2. $ kubectl kruise exec mypod -S sidecar-container -i -t -- bash

scaledown

Scaledown a cloneset with selective Pods.

  1. # Scale down 2 with selective pods
  2. $ kubectl kruise scaledown cloneset/nginx --pods pod-a,pod-b

It will decrease replicas=replicas-2 of this cloneset and delete the specified pods.