-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c90cb1
commit 87f7823
Showing
8 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# kubectl oneliners | ||
These scripts can be used as subcommands for kubectl to serve a specific purpose | ||
## Installation | ||
```bash | ||
sudo cp ./kubectl-* /usr/local/bin/ | ||
``` | ||
|
||
## Desciption | ||
### kubectl-resources | ||
This oneliner shows you the resource limits/requests for pods in a namespace or all namespaces | ||
|
||
Usage example: | ||
```shell | ||
# Supports --all-namespaces | ||
kubectl resources | ||
``` | ||
### kubectl-containerids | ||
This oneliner shows you the associated containerids for kubernetes pods. | ||
It can be used to debug a container directly on the node. The containerId matches the ID on the node itsself | ||
|
||
Usage example: | ||
```shell | ||
# Supports --all-namespaces | ||
kubectl containerids | ||
``` | ||
### kubectl-geteverything | ||
This oneliner shows all (and by that it means every resource/cr) in a namespace. | ||
It requires an argument which is the name of the namespace in question. | ||
|
||
It may be used to debug a namespace stuck in terminating state to find out which resources remain. | ||
|
||
Usage exmaple: | ||
```shell | ||
kubectl geteverything my-namespace | ||
``` | ||
### kubectl-finalize-namespace | ||
This is a dangerous script but sometimes necessary to get rid of a namespace which is stuck in Terminating state | ||
|
||
**Run this script with extrem caution!** | ||
|
||
Usage example: | ||
```shell | ||
kubectl finalize namespace some-namespace --yes-i-really-mean-it | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kubectl get pods --all-namespaces --field-selector spec.nodeName= | ||
git config --global push.autoSetupRemote true | ||
select pg_size_pretty(pg_database_size('db_name')); | ||
stern | ||
kubectx/kubens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
kubectl get pods -o custom-columns="NAMESPACE:.metadata.namespace,POD:.metadata.name,CONTAINER:.spec.containers[*].name,containerIds:.status.containerStatuses[*].containerID" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
if [ -z "$1" ]; then | ||
echo "No argument supplied. You have to supply a namespace you wish to terminate as argument" | ||
exit 1 | ||
fi | ||
if [ "x--yes-i-really-mean-itx" != "x$2x" ]; then | ||
echo "Doing nothing... use --yes-i-really-mean-it if you want to run the script" | ||
exit 1 | ||
fi | ||
kubectl get namespace ${1} -o json \ | ||
| tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \ | ||
| kubectl replace --raw /api/v1/namespaces/${1}/finalize -f - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
kubectl api-resources --verbs=list --namespaced -o name \ | ||
| xargs -n 1 kubectl get --show-kind --ignore-not-found -n $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
# Removes finalizers from resources | ||
patch=$(echo -e 'metadata:\n finalizers: null') | ||
kubectl patch --patch "${patch}" --type=merge $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
kubectl get pods -o custom-columns="NAMESPACE:.metadata.namespace,POD:.metadata.name,CONTAINER:.spec.containers[*].name,REQ_CPU:.spec.containers[*].resources.requests.cpu,LIM_CPU:.spec.containers[*].resources.limits.cpu,REQ_MEM:.spec.containers[*].resources.requests.memory,LIM_CPU:.spec.containers[*].resources.limits.memory" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
NODENAME=$1 | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: node-shell-${NODENAME} | ||
namespace: kube-system | ||
spec: | ||
containers: | ||
- name: shell | ||
image: "docker.io/alpine:3.9" | ||
securityContext: | ||
privileged: true | ||
command: ["nsenter"] | ||
args: ["-t", "1", "-m", "-u", "-i", "-n", "sleep", "14000"] | ||
hostIPC: true | ||
hostNetwork: true | ||
hostPID: true | ||
terminationGracePeriodSeconds: 0 | ||
restartPolicy: Never | ||
tolerations: | ||
- operator: Exists | ||
nodeName: ${NODENAME} | ||
EOF | ||
|
||
sleep 10 | ||
|
||
kubectl exec -it -n kube-system node-shell-${NODENAME} -- /bin/bash | ||
|
||
#kubectl delete pod -n kube-system node-shell-${NODENAME} |