Skip to content

Latest commit

 

History

History
161 lines (114 loc) · 2.72 KB

File metadata and controls

161 lines (114 loc) · 2.72 KB

Command to know

Just some random commands that may help a lot..

Linux basic stuff

Create aliases to be faster

alias ll='ls -l’

Curl:

  • curl -k (allow insecure)
  • curl -v (verbose)

grep recursively (usefull for troubleshooting):

grep -r "searchTerm" /path/to/directory

grep OR / AND:

grep -E “this|orThis”
grep "error" logfile.txt | grep "database"

netstat: list active network connections and listening ports

sudo netstat -tuln

See permission of a file (numeric) :

stat -c "%a"

Checksum

sha512sum file.txt

Kubernetes basics

See extended information about pods:

kubectl get pods -o wide

See short name of a resource:

kubectl api-resources

Explain a resource and its fields:

kubectl explain <resource>

create a simple pod with a single container:

kubectl run mypod --image=nginx

Exec bash into a container:

kubectl exec -it mypod -- bash

Exec a command into a container:

kubectl exec -it POD_NAME_2 -- stress --cpu 1 &

Note: & is used to run the command in the background, so you can continue using the terminal.

Create a pod to only execute a command and exit:

kubectl run mypod --rm -it --image=busybox:1 --restart=Never -- sh

Secret values must be base64 encoded when editing the Secret directly.

echo -n "db.internal" | base64

Containers and Kubernetes

Podman:

podman build -t registry.killer.sh:5000/image-verify:v2 .
podman run registry.killer.sh:5000/image-verify:v2 # to test your changes
podman push registry.killer.sh:5000/image-verify:v2

Check user RBAC

k auth can-i list secret --as gianna

How add a command into a pod:

command: ["/bin/sh", "-c", "echo aba997ac-1c89-4d64 > /mount/config && sleep infinity"]

(if there is one to remember, this is the one, it will cover the other cases)

command: ["sleep", "10"]
command: ["echo"]      # executed command
args: ["Hello, World"] # arguments
command: ["/bin/sh", "-c"]
args: ["echo 'Nginx Started'; nginx -g 'daemon off;'"]

grep all image used in a namespace / in a deployment

k get pods -n nato -o yaml | grep "image: "
k get deploy xym -o yaml | grep "image: "

Get all field of a security context:

kubectl explain pod.spec.securityContext --recursive

Crictl: interacting with Container Runtime Interface (CRI)-compatible container runtimes

# show all containers, including stopped ones
crictl ps -a
crictl inspect <container id>

add label to a pod during creation:

kubectl run mypod --image=nginx --labels="app=myapp,env=dev"
kubectl run mypod --image=nginx -l app=myapp,env=dev