This plugin useful for Bulk operations.
You can easily do bulk operations on all resource types like deployments, services, pods etc.
Bulk plugin
has two part, first you select resources with bulk command, then chose your command (get,delete .. etc.) with parameters.
kubectl bulk <get resourceTypes> (get|list|create|update|delete|remove|rollout) <command parameters>
kubectl bulk pod --all-namespace get image
kubectl bulk deployment -n test get allowPrivilegeEscalation
Now you can use % wild card in get resource types
kubectl bulk po my-pod% -n test update mylabel newValue
Bulk plugin
has 5 main abilities for now :-)
bulk .. get
gets selected fields's values for given resource types.bulk .. list
lists all resource definitions in yaml or json.bulk .. create
creates new resource from your exist resources.bulk .. update
updates bulk resource definitions fields.bulk .. delete
delete bulk resources with delete parameters.bulk .. remove
remove bulk resource definitions fields.bulk .. rollout
rollouts given processes.bulk .. scale
scale given resources.
bulk get
bulk .. get
automatically get resources name, you don't need to add for all command
!!Warning!! bulk .. get
create a temporary file in path for performance.
# get fields' values for given resource type
kubectl bulk <resourceType> [<parameters>] get [<fields>]
$ kubectl bulk hpa -n myspace get minReplicas maxReplicas
minReplicas maxReplicas fields are getting
name: podinfo
maxReplicas: 10
minReplicas: 2
name: sample-metrics-app-hpa
maxReplicas: 10
minReplicas: 2
$ kubectl bulk service get file json
All definitions will be written in file.json
bulk list
bulk .. list
default mode for Bulk plugin
# list all resource definitions in yaml (default format) format
kubectl bulk <resourceType> [<parameters>]
# list all resource definitions in json format
kubectl bulk <resourceType> [<parameters>] list json
# list all resource definitions in to a file with json format
kubectl bulk <resourceType> [<parameters>] list filename json
$ kubectl bulk deployment -n test
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
kind: Deployment
name: sample-app
...
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
kind: Deployment
name: another-sample-app
...
$ kubectl bulk service list file json
All definitions will be written in file.json
bulk create
bulk .. create
get your resource definitions and change metadata fields (name,namespaces) as you defined then create the new resources.
!!Warning!! If that parameter not found (with/out value) than nothing will be changed/created. Standard not created error will be throwed.
# get all definitions and create resources with definitions that parameterName fields changed has oldValue with newValue
kubectl bulk <resourceType>[<parameters>] create parameterName oldValue newValue
# get all definitions and create resources with definitions that parameterName fields removed and added with newValue
kubectl bulk <resourceType>[<parameters>] create parameterName newValue
** Copy all statefulset from test to staging namespaces
$ kubectl bulk statefulset -n test create namespace test staging
creating new resource with changing namespace: test to namespace: staging for all deploy
deployment.extensions/sample-app created
deployment.extensions/another-sample-app created
bulk update
bulk .. update
get your resource definitions and change any fields as you defined then update resource definitions.
!!Warning!! If that parameter not found (with/out value) than nothing will be changed/updated. Standard not updated error will be throwed.
# get all definitions and update resources with definitions that parameterName fields changed has oldValue with newValue
kubectl bulk <resourceType>[<parameters>] update parameterName oldValue newValue
# get all definitions and update resources with definitions that parameterName fields removed and added with newValue
kubectl bulk <resourceType>[<parameters>] update parameterName newValue
# Update all deploys image value in test namespace which image version was v1
$ kubectl bulk deploy -n test update image v1 v2
updating resource with changing image: v1 to image: v2 for all deploy -n test
deployment.extensions/deploy-1 replaced
deployment.extensions/deploy-2 replaced
deployment.extensions/deploy-3 replaced
...
# Update all deploys image value in test namespace with v4
$ kubectl bulk deploy -n test update image v4
updating resource with image: v5 for all deploy
deployment.extensions/deploy-1 replaced
deployment.extensions/deploy-2 replaced
deployment.extensions/deploy-3 replaced
bulk delete
bulk .. delete
easy way to bulk delete resources or fields.
# delete resources that in requested resource types
kubectl bulk <resourceType> [<parameters>] delete
# delete fields of resources that in requested resource types
kubectl bulk <resourceType> [<parameters>] delete <delete parameters>
$ kubectl bulk service -n test delete
service/svc-1 deleted
service/svc-2 deleted
...
$ kubectl bulk deploy delete --grace-period=1
deployment.extensions/deploy-1 deleted
deployment.extensions/deploy-2 deleted
bulk remove
bulk .. remove
easy way to bulk remove resource/fields.
# delete resources that in requested resource types
kubectl bulk <resourceType> [<parameters>] remove
# delete fields of resources that in requested resource types
kubectl bulk <resourceType> [<parameters>] remove <field> <value>
$ kubectl bulk service -n test remove
service/svc-1 deleted
service/svc-2 deleted
...
$ kubectl bulk deploy remove label1
deployment.extensions/deploy-1 replaced
deployment.extensions/deploy-2 replaced
bulk rollout
bulk .. rollout
gives you all rollout features that history|pause|resume|status|undo
!!Reminder!! Rollout feature could be used only these resource types -> deployments|daemonsets|statefulsets
# do rollout for all resources that requested
kubectl bulk <resourceType> [<parameters>] rollout history|pause|resume|status|undo <rollout parameters>
$ kubectl bulk deployment -n test rollout undo
'deploy's are being rollout undo
deployment.extensions/deploy-1
deployment.extensions/deploy-2
$ kubectl bulk deployment -n test rollout history
deployment.extensions/deploy-1
REVISION CHANGE-CAUSE
1 <none>
deployment.extensions/deploy-2
REVISION CHANGE-CAUSE
1 <none>
2 <none>
bulk scale
bulk .. scale
gives you scaling ability to your resources
# scale for all resources that requested
kubectl bulk <resourceType> [<parameters>] scale replicaNumber
$ kubectl bulk deployment -n test scale 3
'deploy's are being scale 1
deployment.extensions/my-deploy scaled
deployment.extensions/test-deploy scaled
deployment.extensions/this-deploy scaled
kubectl it
execute exec, edit, delete and log commands with interactive selection.
- Port-forward ability added
fzf
is required for this plugin.
Usage
$ kubectl it
..
$ kubectl it exec|edit|log|log-follow|delete|port-forward
..
$ kubectl it exec|edit|log|log-follow|delete|port-forward <namespace>
kubectl plugin to simplify interactive exec command.
Lists Kubernetes objects to choose from to create kubectl exec -ti command.
fzf
is required for this plugin.
Install krew plugin manager for kubectl.
kubectl krew install bulk-action
Kubectl-plugins
are Bash scripts, it would be work in any POSIX environment that has Bash installed.
sed|grep|awk are prerequisite commands for kubectl bulk
fzf
is required for kubectl it
and kubectl ixec
!!WARNING!! Kubectl has plugin feature with version 12. Don't forget to update your kubectl installation :)
sudo git clone https://github.com/emreodabas/kubectl-plugins /opt/kubectl-plugins
sudo ln -s /opt/kubectl-plugins/kubectl-bulk /usr/local/bin/kubectl-bulk
sudo ln -s /opt/kubectl-plugins/kubectl-ixec /usr/local/bin/kubectl-ixec
sudo ln -s /opt/kubectl-plugins/kubectl-it /usr/local/bin/kubectl-it
sudo ln -s /opt/kubectl-plugins/kubectl-mi /usr/local/bin/kubectl-mi
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install