Difference between revisions of "Kubectl"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 18: Line 18:
 
https://gist.github.com/zparnold/0e72d7d3563da2704b900e3b953a8229
 
https://gist.github.com/zparnold/0e72d7d3563da2704b900e3b953a8229
  
 +
 +
```
 +
kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" |\
 +
tr -s '[[:space:]]' '\n' |\
 +
sort |\
 +
uniq -c
 +
 +
kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}"
 +
```
  
 
# On Microk8s Quick
 
# On Microk8s Quick
Line 42: Line 51:
 
sudo zfs create zfspv-pool/bkp
 
sudo zfs create zfspv-pool/bkp
 
sudo kubectl cp postgres0-0:/var/lib/postgresql/data /zfspv-pool/bkp/data -n postgres-dev
 
sudo kubectl cp postgres0-0:/var/lib/postgresql/data /zfspv-pool/bkp/data -n postgres-dev
 +
```
 +
 +
Delete all from namespace
 +
```
 +
kubectl delete all --all -n default
 +
```
 +
 +
Delete all replicate sets
 +
```
 +
kubectl delete replicaset $(kubectl get replicaset -o jsonpath='{ .items[?(@.spec.replicas==0)].metadata.name }')
 
```
 
```

Latest revision as of 18:51, 4 April 2023

kubectl delete pods --field-selector status.phase=Failed --all-namespaces
kubectl describe node foo
kubectl run my-testshell --rm -i --tty --image ubuntu -- bash
kubectl delete pods --field-selector status.phase=Failed --all-namespaces

https://gist.github.com/zparnold/0e72d7d3563da2704b900e3b953a8229

kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c

kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}"

On Microk8s Quick

mkdir $HOME/.kube
microk8s config > $HOME/.kube/config
snap install kubectl --classic
kubectl get nodes

or alias

alias kubectl='sudo microk8s.kubectl'
alias k='sudo microk8s.kubectl'

clean-up non-running/evicted/ContainerStatusUnknown pods in example namespace

for i in $(kubectl -n zabbix-prod get pods --no-headers | grep -v "Run" | awk '{print $1}'); do kubectl -n example delete pod $i; done
sudo zfs create zfspv-pool/bkp
sudo kubectl cp postgres0-0:/var/lib/postgresql/data /zfspv-pool/bkp/data -n postgres-dev

Delete all from namespace

kubectl delete all --all -n default

Delete all replicate sets

kubectl delete replicaset $(kubectl get replicaset -o jsonpath='{ .items[?(@.spec.replicas==0)].metadata.name }')