0
0
Kubernetesdevops~10 mins

Init containers in Kubernetes - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an init container in a Pod spec.

Kubernetes
initContainers:
  - name: init-myservice
    image: busybox
    command: ["[1]", "-c", "echo Init container running"]
Drag options to blanks, or click blank then click option'
Abash
Bsh
Csleep
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' which is not a shell command
Using 'sleep' which delays but does not run commands
Using 'bash' which may not be available in busybox
2fill in blank
medium

Complete the code to specify the init container image.

Kubernetes
initContainers:
  - name: init-db
    image: [1]
Drag options to blanks, or click blank then click option'
Abusybox:1.35
Bnginx:latest
Cmysql:5.7
Dredis:alpine
Attempts:
3 left
💡 Hint
Common Mistakes
Using application images like nginx or mysql which are not typical for init containers
3fill in blank
hard

Fix the error in the init container command to run a shell script.

Kubernetes
initContainers:
  - name: setup
    image: busybox
    command: ["[1]", "-c", "echo Setup complete"]
Drag options to blanks, or click blank then click option'
Ash
Bbash
Ccmd
Dpowershell
Attempts:
3 left
💡 Hint
Common Mistakes
Using bash which may not be present
Using Windows shells like cmd or powershell which are invalid here
4fill in blank
hard

Fill both blanks to define an init container that waits for a file before starting the main container.

Kubernetes
initContainers:
  - name: wait-for-file
    image: busybox
    command: ["[1]", "-c", "until test -f /tmp/ready; do [2] 1; done"]
containers:
  - name: main-app
    image: myapp
    volumeMounts:
      - name: shared-data
        mountPath: /tmp
volumes:
  - name: shared-data
    emptyDir: {}
Drag options to blanks, or click blank then click option'
Ash
Bbash
Csleep
Dcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using bash which may not be in busybox
Using cat which does not pause
Using sleep as the command instead of inside the shell command
5fill in blank
hard

Fill all three blanks to create an init container that creates a directory and sets permissions before the main container starts.

Kubernetes
initContainers:
  - name: setup-dir
    image: busybox
    command: ["[1]", "-c", "mkdir -p /data [3] [2] 777 /data && echo Directory ready"]
    volumeMounts:
      - name: data-volume
        mountPath: /data
containers:
  - name: app
    image: myapp
    volumeMounts:
      - name: data-volume
        mountPath: /data
volumes:
  - name: data-volume
    emptyDir: {}
Drag options to blanks, or click blank then click option'
Ash
Bchmod
C&&
Dbash
Attempts:
3 left
💡 Hint
Common Mistakes
Using bash which may not be available
Using single & instead of && which causes syntax errors
Using wrong commands for permissions