CKA: Essential Shell commands

Vishnu MohanVishnu Mohan
5 min read
  1. Redirection operators(>> vs >) : > and >> are redirection operators used to send output to files instead of the terminal. Here's what they mean:

    1. > : Redirect and Overwrite

      • Redirects stdout (standard output) to a file.

      • Overwrites the file if it exists.

    2. >> : Redirect and Append

      • Redirects stdout to a file.

      • Appends to the file if it exists.

      • Creates the file if it doesn't exist.

  2. tail utility : The tail utility is a command-line tool used to display the end (tail) of a file, usually text files like logs, defaults to displaying the last 10 lines of a file.

    • -f flag in tail -f stands for "follow", which means: shows the last 10 lines and then keep the file open and continuously output new lines as they are appended to the file.
  3. dpkg : A low-level tool that Installs .deb files without dependency resolution.

  4. apt-get : A package manager used to install/remove/update packages which can resolve dependencies and fetch packages from online repositories (which dpkg cannot).

  5. systemctl : The command-line tool used to interact with systemd, the modern init system and service manager used in most major Linux distributions (like Ubuntu, CentOS, Debian, RHEL, etc.)

    • Used to manage systemd services (start/stop services, enable at boot, etc.).

        # Start, stop, restart, enable, disable, and check the status of services.
        systemctl start nginx          # Start nginx service
        systemctl stop nginx           # Stop it
        systemctl restart nginx        # Restart
        systemctl status nginx         # Show current status
        systemctl enable nginx         # Start nginx automatically at boot
        systemctl disable nginx        # Disable it from auto-starting
      
  6. grep : Global Regular Expression Print, go-to utility for searching text in files, logs, or command output using patterns or regular expressions.

    • -i flag for case-insensitive search

    • -r or -R for recursive search in all files in a directory

    • -n shows line numbers of matching lines

    • -w will match whole words only

    • --color for highlighting the match in the output

    •           # eg, how to combine it with kubectl for debugging
                kubectl get pods -A | grep CrashLoopBackOff
      
  7. sysctl : Used to view or modify kernel parameters (like net.ipv4.ip_forward).

    •       sysctl net.ipv4.ip_forward          # Check value
            sysctl -w net.ipv4.ip_forward=1     # Set temporarily
      
  8. sudo −i: sudo utility in Linux systems lets you run commands with elevated privileges, typically as the root (superuser) account, without having to log in as root directly

    • Although it stands for “superuser do“, now it can be configured to let you run commands as any user, not just root

    • sudo -i is a special form of sudo that gives you an interactive root login shell, almost as if you logged in directly as the root user

  9. curl & wget: Both curl and wget are command-line utilities for transferring data over networks

    • curl: Transfers data to/from a server using many supported protocols (HTTP, HTTPS, FTP, SFTP, SCP, LDAP, IMAP, POP3, SMTP, etc)

    • It’s actually a general-purpose HTTP/HTTPS client for making requests to any endpoint.

    • wget: Primarily for downloading files from the web (HTTP, HTTPS, FTP).

    • While curl is very flexible for both download and upload, it is mostly used for making http request in CKA; wget is designed mainly for retrieving content, especially useful for big files or recursive site downloads.

  10. nslookup: command-line tool used to query DNS (Domain Name System) servers to get information about domain names, IP addresses, and other DNS records.

    • Looks up the IP address for a given domain name and vice-versa (reverse lookup).

    • Retrieves specific DNS record types (A, AAAA, MX, TXT, NS, etc.).

    • Useful for testing or troubleshooting DNS configuration issues.

  11. netstat : Displays active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP routing table, IPv4 statistics.

    • Shows active TCP/UDP connections (both incoming and outgoing).

    • Lists ports the system is listening on.

    • Displays routing tables.

    • Shows network interface statistics (packets sent/received, errors).

    • Helps identify which process is using which port.

    • netstat -tulnp is used to display all actively listening TCP and UDP ports, along with the processes using them.


Good to know

  1. kubectl --help: shows the you the built-in usage guide for kubectl including all the subcommands and options

    • My favourite and super helpful during the exam, saves a lot of time wasted searching through docs.
  2. yq: command-line utility for reading, writing, and transforming YAML file

    • yq can be a big time-saver when working with YAML manifests for Kubernetes

    • For example: use yq '.spec.containers[].image' pod.yaml for grabbing image of pod

  3. man: displays the manual pages for commands, basically the built-in, offline reference guide for most CLI tools

    • Useful for instantly check syntax for CLI tools right in the terminal
  4. kubectl explain: shows the API schema for any Kubernetes object

    • Helpful when working with custom CRDs as CRDs docs are not available in the official exam

    • Using explain subcommand we can see the details of our API schema such as field names and descriptions


Most of the utilities listed here are used by SysAdmins and DevOps folks on day to day basis, however having it listed out like this could be a good reference during preparation.

This list is not exhaustive, let me know if I’ve missed any commands so that I can keep the list updated as much as possible!! 🤞

1
Subscribe to my newsletter

Read articles from Vishnu Mohan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vishnu Mohan
Vishnu Mohan

Software Engineer | DevOps & CloudNative