Bird
Raised Fist0
Kubernetesdevops~10 mins

etcd backup and recovery in Kubernetes - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to create a snapshot backup of etcd.

Kubernetes
ETCDCTL_API=3 etcdctl snapshot save [1]
Drag options to blanks, or click blank then click option'
A/etc/etcd/etcd.conf
B/var/lib/etcd/backup.db
C/usr/local/bin/etcd
D/var/log/etcd.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using a directory path instead of a file path.
Using a config or log file path instead of a backup file.
2fill in blank
medium

Complete the command to check the status of the etcd cluster.

Kubernetes
ETCDCTL_API=3 etcdctl endpoint [1]
Drag options to blanks, or click blank then click option'
Amember
Bbackup
Crestore
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'backup' or 'restore' which are unrelated to status checking.
Using 'member' which lists cluster members but not status.
3fill in blank
hard

Fix the error in the restore command by completing the missing flag.

Kubernetes
ETCDCTL_API=3 etcdctl snapshot restore backup.db [1] /var/lib/etcd-new
Drag options to blanks, or click blank then click option'
A--data-dir
B--backup-dir
C--config-file
D--log-dir
Attempts:
3 left
💡 Hint
Common Mistakes
Using --backup-dir which is not a valid flag for restore.
Confusing data directory with config or log directories.
4fill in blank
hard

Fill both blanks to set environment variables for etcdctl to connect securely.

Kubernetes
export ETCDCTL_API=3
export ETCDCTL_ENDPOINTS=[1]
export ETCDCTL_CACERT=[2]
Drag options to blanks, or click blank then click option'
Ahttps://127.0.0.1:2379
B/etc/ssl/etcd/ca.crt
C/var/lib/etcd/data
Dhttp://localhost:2380
Attempts:
3 left
💡 Hint
Common Mistakes
Using HTTP instead of HTTPS for secure connection.
Using data directory path instead of CA certificate path.
5fill in blank
hard

Fill all three blanks to create a snapshot, check its status, and restore it to a new directory.

Kubernetes
ETCDCTL_API=3 etcdctl snapshot save [1]
ETCDCTL_API=3 etcdctl endpoint status --write-out=table
ETCDCTL_API=3 etcdctl snapshot restore [2] [3]
Drag options to blanks, or click blank then click option'
A/var/backups/etcd-snapshot.db
C--data-dir /var/lib/etcd-restored
D--data-dir /var/lib/etcd-new
Attempts:
3 left
💡 Hint
Common Mistakes
Using different snapshot file names for save and restore.
Omitting the --data-dir flag or using wrong directory.

Practice

(1/5)
1. What is the primary purpose of taking an etcd backup in Kubernetes?
easy
A. To save the current state of the cluster data safely
B. To update the Kubernetes version automatically
C. To monitor cluster performance metrics
D. To delete old cluster data permanently

Solution

  1. Step 1: Understand etcd role in Kubernetes

    etcd stores all cluster data including configuration and state.
  2. Step 2: Purpose of backup

    Backing up etcd saves this data so it can be restored if lost or corrupted.
  3. Final Answer:

    To save the current state of the cluster data safely -> Option A
  4. Quick Check:

    Backup = Save cluster data [OK]
Hint: Backup means saving cluster data safely [OK]
Common Mistakes:
  • Confusing backup with updating Kubernetes
  • Thinking backup monitors performance
  • Assuming backup deletes data
2. Which of the following is the correct command to create an etcd snapshot backup?
easy
A. etcdctl save snapshot backup.db
B. etcdctl backup create backup.db
C. etcdctl snapshot create backup.db
D. etcdctl snapshot save backup.db

Solution

  1. Step 1: Recall etcdctl snapshot save syntax

    The correct command to save a snapshot is etcdctl snapshot save <file>.
  2. Step 2: Compare options

    Only etcdctl snapshot save backup.db matches the exact syntax.
  3. Final Answer:

    etcdctl snapshot save backup.db -> Option D
  4. Quick Check:

    Snapshot save = create backup [OK]
Hint: Use 'etcdctl snapshot save' to backup [OK]
Common Mistakes:
  • Using 'backup create' instead of 'snapshot save'
  • Mixing 'create' and 'save' commands
  • Incorrect command order
3. What will be the output of the following command if the backup file backup.db exists and is valid?

etcdctl snapshot restore backup.db --data-dir restored-etcd
medium
A. Restores the snapshot data into the directory 'restored-etcd'
B. Creates a new snapshot named 'restored-etcd'
C. Deletes the existing backup.db file
D. Shows an error that the file does not exist

Solution

  1. Step 1: Understand snapshot restore command

    The command restores data from a snapshot file into a specified data directory.
  2. Step 2: Analyze given command

    It uses backup.db as source and restores into restored-etcd directory.
  3. Final Answer:

    Restores the snapshot data into the directory 'restored-etcd' -> Option A
  4. Quick Check:

    Restore command = recover data to directory [OK]
Hint: Restore puts data into given directory [OK]
Common Mistakes:
  • Thinking it creates a new snapshot
  • Assuming it deletes backup files
  • Expecting error when file exists
4. You ran etcdctl snapshot save backup.db but the command failed with an error: etcdctl: command not found. What is the most likely cause?
medium
A. The command syntax is incorrect
B. The etcdctl tool is not installed or not in the system PATH
C. The etcd server is down and cannot create a snapshot
D. The backup.db file already exists and cannot be overwritten

Solution

  1. Step 1: Analyze error message

    The error 'command not found' means the system cannot find the etcdctl program.
  2. Step 2: Identify cause

    This usually happens if etcdctl is not installed or not in the PATH environment variable.
  3. Final Answer:

    The etcdctl tool is not installed or not in the system PATH -> Option B
  4. Quick Check:

    Command not found = tool missing or PATH issue [OK]
Hint: Command not found means tool missing or PATH error [OK]
Common Mistakes:
  • Assuming file overwrite causes command not found
  • Blaming etcd server status for command not found
  • Thinking syntax error causes command not found
5. You want to recover your Kubernetes cluster after a failure using an etcd snapshot. Which sequence of commands correctly restores the cluster data and starts etcd with the restored data?
hard
A. systemctl restart etcd && etcdctl snapshot restore backup.db --data-dir /var/lib/etcd-restored
B. etcdctl snapshot save backup.db && systemctl stop etcd
C. etcdctl snapshot restore backup.db --data-dir /var/lib/etcd-restored && systemctl restart etcd
D. etcdctl snapshot restore backup.db --data-dir /var/lib/etcd-restored && systemctl stop etcd

Solution

  1. Step 1: Restore snapshot to a new data directory

    Use etcdctl snapshot restore backup.db --data-dir /var/lib/etcd-restored to recover data safely without overwriting live data.
  2. Step 2: Restart etcd service to use restored data

    Restarting etcd with systemctl restart etcd applies the restored data directory.
  3. Final Answer:

    etcdctl snapshot restore backup.db --data-dir /var/lib/etcd-restored && systemctl restart etcd -> Option C
  4. Quick Check:

    Restore then restart etcd = recovery [OK]
Hint: Restore snapshot first, then restart etcd service [OK]
Common Mistakes:
  • Restarting etcd before restoring snapshot
  • Stopping etcd without restarting after restore
  • Saving snapshot instead of restoring