Advanced
Searching inSummaries
How to search
  • Words find lesson titles, text and code. Filter by type (guides, courses, programs, books) or stay in this book.
  • book:rhcsa and ch:8 narrow the search; #code finds a word only in commands of the lessons.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Chapter 13Name in the course: The top 10 commands

The 10 command-line tools you use every day

Out of all DevOps tools, ten command-line tools come back in almost every job, every pipeline and every incident: git, docker, kubectl, helm, terraform, ansible, aws, az, ssh and curl. This chapter gives each one in a short card — what it is for, the sub-commands you need first and one real example. Each card links to the full command page with every sub-command, the important options, 10+ real examples, warnings, files and exit codes.

  • 13 Lessons
  • 21 Commands
  • 1 Labs

$ run as a normal user# run as root (or with sudo)

Skills in this chapter

  • The 10 everyday command-line tools — full pages

13.1

Know the 10 tools and how they connect

Code goes into git, is packed by docker, is created in the cloud by terraform (with aws or az), is configured by ansible, runs on Kubernetes through kubectl and helm, and is checked with ssh and curl.

#ToolJobFull page
1gitVersion control: every change, branch and releasegit
2dockerBuild and run container imagesdocker
3kubectlControl a Kubernetes clusterkubectl
4helmInstall and upgrade apps on Kuberneteshelm
5terraformBuild cloud infrastructure from codeterraform
6ansibleConfigure servers over SSHansible
7awsControl Amazon Web Servicesaws
8azControl Microsoft Azureaz
9sshSecure login, tunnels and file copyssh
10curlTest web servers and APIscurl

Remember

You do not learn every option by heart. Learn the first sub-commands of each card, and know where the full page is.

13.2

git — every change in one history

Git saves snapshots of your project. Branches keep work apart; pull requests and pipelines start from Git.

Sub-commandUse it to
clone, initGet or start a repository
status, diff, add, commitSee and save changes
switch -c, merge, rebaseWork with branches
fetch, pull, pushSync with GitHub, GitLab, Azure Repos
log --oneline --graph, blame, reflogRead and rescue the history
tag, revertRelease and undo safely
git switch -c feature/health-check
git add app.py && git commit -m "Add /health endpoint"
git push -u origin feature/health-check

All sub-commands and options: the git page.

Commands in this lesson

13.3

docker — build and run containers

Docker packs an app into an image and runs it as a container — the same on a laptop, a build server and in production.

Sub-commandUse it to
build -t, push, pull, imagesMake and move images
run -d -p, ps, stop, rmRun and manage containers
logs -f, exec -it, inspect, statsLook inside and debug
volume, networkKeep data, connect containers
compose up -d, compose downRun a stack from one YAML file
buildx build --platform, system pruneMulti-CPU builds, clean up
docker build -t ghcr.io/s0sta/shop:1.4.0 .
docker run -d --name shop -p 127.0.0.1:8080:8080 ghcr.io/s0sta/shop:1.4.0
docker logs -f shop

All sub-commands and options: the docker page.

13.4

kubectl — talk to Kubernetes

kubectl reads and changes every object in a cluster. Apply YAML from Git; use describe and logs when something fails.

Sub-commandUse it to
get, describe, explainSee objects and their events, learn fields
apply -f, diff -f, deleteDeploy the wanted state
rollout status / undo, scale, set imageUpdate and roll back
logs, exec -it, port-forward, debugDebug Pods
config use-context, auth can-iChoose the cluster, check RBAC
cordon, drain, topNode maintenance and load
kubectl apply -f k8s/
kubectl rollout status deploy/shop
kubectl describe pod -l app=shop | tail -20

All sub-commands and options: the kubectl page.

13.5

helm — packages for Kubernetes

Helm installs a chart (templates + values) as a release, and every upgrade can be rolled back.

Sub-commandUse it to
repo add, repo update, search repoFind charts
show values, template, lintCheck a chart before installing
upgrade --install --atomicInstall or upgrade the same way every time
list, status, history, get valuesSee releases
rollback, uninstallGo back or remove
package, push oci://Ship your own charts
helm upgrade --install shop ./charts/shop -n shop -f values/prod.yaml --atomic --wait
helm history shop -n shop

All sub-commands and options: the helm page.

13.6

terraform — infrastructure as code

Terraform compares your .tf files with the real cloud and the state, shows a plan, and applies only the difference.

Sub-commandUse it to
init, fmt, validatePrepare and check the folder
plan -out, apply PLANReview and make the change
state list / show / mv, importWork with the state
output, show, consoleRead values and test expressions
workspace, destroySeveral states, remove a stack
terraform init && terraform plan -out=tfplan
terraform apply tfplan

All sub-commands and options: the terraform page.

13.7

ansible — configure many servers

Ansible runs idempotent modules over SSH from playbooks, so a second run changes nothing when the servers are already right.

CommandUse it to
ansible all -m pingTest access to every host
ansible-playbook site.yml --check --diffPreview, then run playbooks
ansible-inventory --graphSee hosts and groups
ansible-galaxy collection installGet modules and roles
ansible-vault create / editKeep secrets encrypted
ansible-doc MODULERead a module's options
ansible-playbook -i inventory.ini site.yml -l web --check --diff
ansible-playbook -i inventory.ini site.yml -l web

All commands, modules and options: the ansible page.

13.8

aws — Amazon Web Services from the terminal

aws SERVICE OPERATION reaches every AWS service; --query and --output make the answers easy for people and scripts.

CommandUse it to
configure sso, sts get-caller-identityLog in and check who you are
ec2 describe-instances --filters --queryFind servers
s3 cp, s3 syncMove files and backups
ecr get-login-password, eks update-kubeconfigContainers and Kubernetes
ssm start-session, logs tail --followReach servers and read logs
aws sso login --profile prod && aws sts get-caller-identity --profile prod
aws s3 sync ./public s3://s0sta-site --delete --dryrun

All services and options: the aws page.

Commands in this lesson

13.9

az — Microsoft Azure from the terminal

az GROUP COMMAND manages Azure: resource groups, VMs, networks, storage, AKS, Key Vault and RBAC.

CommandUse it to
login, account set, account showLog in and pick the subscription
group create, deployment group createResource groups and Bicep/ARM
vm create, network vnet / nsgServers and networks
storage blob upload, keyvault secret setFiles and secrets
acr build, aks get-credentialsContainers and Kubernetes
role assignment createGive exactly the access needed
az account show -o table
az aks get-credentials -g rg-shop-prod -n aks-shop

All command groups and options: the az page.

Commands in this lesson

13.10

ssh — secure access to servers

SSH gives an encrypted shell, file copy and tunnels. Keys instead of passwords, and a jump host for private networks.

CommandUse it to
ssh user@hostLog in
ssh-keygen -t ed25519, ssh-copy-idMake and install a key
ssh -J bastion web1Go through a jump host
ssh -L 5432:db:5432 bastionReach a private service locally
scp, rsync -e sshCopy files
~/.ssh/configSave hosts, users, keys and jump hosts
ssh-keygen -t ed25519 -C "hosam@laptop"
ssh -J deploy@bastion deploy@10.10.1.5

All options: the ssh page, plus ssh-keygen and scp.

13.11

curl — test websites and APIs

curl sends HTTP requests from the terminal: check status codes, headers, TLS, redirects and API answers.

OptionUse it to
-I, -sS -o /dev/null -w '%{http_code}'Check a site and its status code
-L, -vFollow redirects, see the full exchange
-X POST -H -d / --jsonCall an API
--resolve, -kTest a new server before DNS / ignore TLS (tests only)
--retry, --max-timeHealth checks in scripts
curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://s0sta.com/
curl -fsS http://localhost:8080/health || echo "app is down"

All options: the curl page.

13.12

Follow one change through all 10 tools

A normal day: one small change goes from your laptop to production and is checked — and every tool has its place.

  1. Make the change on a branch and push it.
    git switch -c fix/timeout && git commit -am "Raise API timeout" && git push -u origin fix/timeout
  2. The pipeline builds and pushes the image.
    docker build -t acrs0sta.azurecr.io/shop:$(git rev-parse --short HEAD) .
    az acr login -n acrs0sta && docker push acrs0sta.azurecr.io/shop:$(git rev-parse --short HEAD)
  3. The infrastructure is already there (built once with Terraform); check it has no drift.
    terraform plan -detailed-exitcode
  4. Deploy with Helm and watch the rollout with kubectl.
    helm upgrade --install shop ./charts/shop -n shop --set image.tag=$(git rev-parse --short HEAD) --atomic
    kubectl rollout status deploy/shop -n shop
  5. Check the result from outside, and on the old VM that still runs a cron job.
    curl -fsS https://shop.example.com/health
    ssh deploy@vm-web1 'systemctl status shop-cron --no-pager'
    ansible web -m ansible.builtin.command -a "uptime"

At work

Put these steps in a pipeline (GitHub Actions or GitLab CI). The commands are the same; only the trigger changes.

13.13

Check yourself

Short questions about the 10 tools.

1Which command shows the Events of a Pod that does not start?

kubectl describe pod NAME (the Events are at the end).

2Which Terraform pair makes sure only the reviewed change is applied?
3How do you install or upgrade a Helm release with one command, and roll back on failure?
4Which Docker publish option keeps a port reachable only from the same machine?

-p 127.0.0.1:8080:80.

5How do you preview what an Ansible playbook would change?
6How do you check who you are logged in as on AWS and on Azure?
7Which Git push option is the safe way to force-push after a rebase?
8Which curl command prints only the HTTP status code of a site?

Practice

All commands in this chapter