Bird
Raised Fist0
Kubernetesdevops~5 mins

kubectl CLI installation and configuration in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is kubectl in Kubernetes?

kubectl is a command-line tool used to interact with Kubernetes clusters. It lets you create, update, delete, and manage Kubernetes resources.

Click to reveal answer
beginner
How do you install kubectl on a Linux system using curl?

Run these commands:
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/

Click to reveal answer
intermediate
What is the purpose of the kubectl config command?

kubectl config manages the configuration file that stores cluster, user, and context information. It helps kubectl know which cluster to talk to and with what credentials.

Click to reveal answer
beginner
What file does kubectl use by default to store cluster connection info?

By default, kubectl uses the ~/.kube/config file to store cluster, user, and context details.

Click to reveal answer
beginner
How do you check the current context (cluster and user) kubectl is using?

Run kubectl config current-context. It shows the active cluster and user setting.

Click to reveal answer
Which command installs kubectl on Linux using curl?
Acurl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
Bapt-get install kubectl
Cyum install kubectl
Dcurl https://kubectl.io/install.sh
Where does kubectl store its default configuration file?
A/etc/kubernetes/config
B~/.kube/config
C/usr/local/bin/kubectl.conf
D/var/lib/kube/config
What does the command kubectl config current-context show?
AThe current Kubernetes cluster and user context
BThe version of kubectl installed
CThe list of all pods in the cluster
DThe status of the Kubernetes nodes
Which of these is NOT a valid way to configure kubectl?
ARunning <code>kubectl config use-context</code>
BEditing the <code>~/.kube/config</code> file manually
CRunning <code>kubectl install config</code>
DUsing <code>kubectl config set-context</code>
After downloading the kubectl binary, what is the next step to make it executable on Linux?
ARun <code>kubectl config set</code>
BRun <code>kubectl install</code>
CRun <code>sudo apt-get update</code>
DRun <code>chmod +x kubectl</code>
Explain the steps to install and configure kubectl on a new Linux machine.
Think about downloading, permissions, placement, and configuration.
You got /5 concepts.
    Describe how kubectl knows which Kubernetes cluster to connect to.
    Focus on the config file and context concept.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the primary purpose of the kubectl command-line tool in Kubernetes?
      easy
      A. To manage and control Kubernetes clusters from your computer
      B. To build Docker container images
      C. To monitor server hardware performance
      D. To write Kubernetes YAML configuration files

      Solution

      1. Step 1: Understand kubectl's role

        kubectl is designed to interact with Kubernetes clusters, allowing users to deploy, inspect, and manage resources.
      2. Step 2: Differentiate from other tools

        Building Docker images or monitoring hardware are not functions of kubectl. Writing YAML files is done manually or with editors, not by kubectl.
      3. Final Answer:

        To manage and control Kubernetes clusters from your computer -> Option A
      4. Quick Check:

        kubectl manages clusters = D [OK]
      Hint: kubectl controls Kubernetes clusters directly [OK]
      Common Mistakes:
      • Confusing kubectl with Docker commands
      • Thinking kubectl builds container images
      • Assuming kubectl edits YAML files automatically
      2. Which of the following commands correctly downloads the latest stable kubectl binary for Linux and makes it executable?
      easy
      A. curl -O https://kubernetes.io/download/kubectl && chmod +x kubectl
      B. wget https://kubectl.io/latest && chmod 777 kubectl
      C. curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl
      D. apt-get install kubectl && chmod +x /usr/bin/kubectl

      Solution

      1. Step 1: Identify the official download URL and command

        curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl uses the official Kubernetes release URL with a command to get the latest stable version dynamically and downloads the Linux amd64 binary.
      2. Step 2: Check command correctness and permissions

        curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl also correctly applies chmod +x to make the binary executable. Other options use incorrect URLs or commands.
      3. Final Answer:

        curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl -> Option C
      4. Quick Check:

        Official URL + chmod +x = A [OK]
      Hint: Use official Kubernetes URLs with curl and chmod +x [OK]
      Common Mistakes:
      • Using wrong URLs that don't point to kubectl binaries
      • Forgetting to make the binary executable
      • Using package managers that don't have kubectl
      3. After installing kubectl and setting your kubeconfig file, what will the command kubectl config current-context output?
      medium
      A. The version of the kubectl client installed
      B. The name of the current Kubernetes cluster context in use
      C. The list of all pods running in the cluster
      D. The IP address of the Kubernetes master node

      Solution

      1. Step 1: Understand the purpose of kubectl config current-context

        This command shows which cluster context kubectl is currently set to use from the kubeconfig file.
      2. Step 2: Differentiate from other commands

        Listing pods uses kubectl get pods, version uses kubectl version, and IP address is not shown by this command.
      3. Final Answer:

        The name of the current Kubernetes cluster context in use -> Option B
      4. Quick Check:

        current-context shows active cluster = C [OK]
      Hint: current-context shows active cluster name [OK]
      Common Mistakes:
      • Confusing current-context with pod listing
      • Expecting version info from this command
      • Thinking it shows IP addresses
      4. You run kubectl get pods but get the error: error: You must be logged in to the server (Unauthorized). What is the most likely cause?
      medium
      A. kubectl is not installed on your system
      B. You typed the command incorrectly
      C. The Kubernetes cluster is down
      D. Your kubeconfig file is missing or has incorrect credentials

      Solution

      1. Step 1: Analyze the error message

        The error says you must be logged in, which means authentication failed.
      2. Step 2: Identify the cause related to kubeconfig

        This usually happens when the kubeconfig file is missing, corrupted, or has wrong credentials, so kubectl cannot authenticate to the cluster.
      3. Final Answer:

        Your kubeconfig file is missing or has incorrect credentials -> Option D
      4. Quick Check:

        Unauthorized error means kubeconfig issue = B [OK]
      Hint: Unauthorized means kubeconfig or credentials problem [OK]
      Common Mistakes:
      • Assuming kubectl is not installed from this error
      • Thinking cluster is down without checking logs
      • Blaming command syntax for authentication errors
      5. You have multiple Kubernetes clusters and want to switch kubectl to use a different cluster context named dev-cluster. Which command correctly switches the context?
      hard
      A. kubectl config use-context dev-cluster
      B. kubectl switch context dev-cluster
      C. kubectl set context dev-cluster
      D. kubectl change-context --cluster=dev-cluster

      Solution

      1. Step 1: Recall the correct command to switch contexts

        The official command to switch kubectl context is kubectl config use-context <context-name>.
      2. Step 2: Verify other options are invalid

        Options B, C, and D are not valid kubectl commands and will cause errors.
      3. Final Answer:

        kubectl config use-context dev-cluster -> Option A
      4. Quick Check:

        Switch context uses 'config use-context' = A [OK]
      Hint: Switch context with 'kubectl config use-context' [OK]
      Common Mistakes:
      • Using non-existent kubectl commands
      • Confusing 'set' or 'change' with 'use-context'
      • Forgetting to specify the exact context name
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard