kubectl
see also kubernetes. kubectl is the utility to control and manage kubernetes.
copy files from and to pod
copy a file from a pod to the local filesystem:
kubectl cp my-pod-name:/report.xlsx report.xlsxcopy a file from the local filesystem to a pod:
kubectl cp hello.txt my-pod-name:/world.txtdownload kubectl for arm architecture, like an raspberry pi
I don’t know why they make it so hard, but here you go:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm/kubectl"execute command in pod
one-off command:
kubectl exec rabbitmq-0 -- rabbitmqctl list_queuesrun with tty interactively:
kubectl exec -it --tty rabbitmq-0 -- /bin/shget kubernetes event log
…sorted by timestamp
kubectl get events --sort-by=.metadata.creationTimestamppod / deployment memory usage
kubectl top pods -l app=<appname> --no-headers | awk '{SUM += $3} END { print "Total Memory Usage: " SUM " MiB"}'port forwarding
you may want to omit --address=0.0.0.0
kubectl port-forward pod-name-here --address=0.0.0.0 8384:8384get a random local port:
kubectl port-forward pod-name-here --address=0.0.0.0 :8384run cronjob manually
get list of cron jobs:
kubectl get cronjob
# gickup 0 4 * * * [...]run a manual job:
kubectl create job --from=cronjob/gickup gickup-run-manualyou might want to delete the job afterwards:
kubectl delete job gickup-run-manualrun one-off pod
example, run the minio/mc container and override the command to end up in a shell instead of the default mc entrypoint
kubectl run -i --tty mc --image=minio/mc --command /bin/shrun pod with registry secrets
update / replace registry-secret-name and specify your image after --image
kubectl run -i --tty my-container --image=ghcr.io/example/private-image:latest --command /bin/sh --overrides='{ "spec": { "imagePullSecrets": [{"name": "registry-secret-name"}] } }'logs
get all logs of a deployment
given you have a deployment with the label app=your-app-name and multiple pods in there:
kubectl logs -l app=your-app-name --all-containerstail logs
this will read the last 100 log entries and also keep following the log for new entries
kubectl logs -f --tail=100 <pod-name>