XK0-005 Scripting, Containers and Automation • Complete Question Bank
Complete XK0-005 Scripting, Containers and Automation question bank — all 0 questions with answers and detailed explanations.
Refer to the exhibit. ``` $ cat /var/log/containers/web.log | grep "ERROR" | head -5 [2024-03-21 10:15:23] ERROR: Connection refused to database at 10.0.0.1:3306 [2024-03-21 10:15:24] ERROR: Connection refused to database at 10.0.0.1:3306 [2024-03-21 10:15:25] ERROR: Connection refused to database at 10.0.0.1:3306 [2024-03-21 10:15:26] ERROR: Connection refused to database at 10.0.0.1:3306 [2024-03-21 10:15:27] ERROR: Connection refused to database at 10.0.0.1:3306 ```
Refer to the exhibit. ``` $ cat Dockerfile FROM ubuntu:22.04 RUN apt-get update && apt-get install -y nginx COPY index.html /var/www/html/ EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] $ docker build -t webapp . $ docker run -d -p 8080:80 webapp ```
Refer to the exhibit. ``` $ crontab -l */5 * * * * /usr/local/bin/healthcheck.sh ```
Refer to the exhibit. # kubectl get pods -l app=web NAME READY STATUS RESTARTS AGE web-0 1/1 Running 0 10m web-1 1/1 Running 0 10m web-2 0/1 CrashLoopBackOff 3 5m # kubectl describe pod web-2 ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Pulled 5m kubelet Container image "web-app:1.0" already present on machine Normal Created 5m kubelet Created container web Normal Started 5m kubelet Started container web Warning BackOff 2m kubelet Back-off restarting failed container Warning CrashLoopBackOff 1m kubelet CrashLoopBackOff
A Linux administrator is responsible for a critical application that runs as a systemd service on a server. The application occasionally hangs, and the administrator wants to automate the restart if the service becomes unresponsive. The administrator writes a Bash script that checks if the service is active and responsive by pinging a local health endpoint. If the health check fails three consecutive times, the script restarts the service. The script is intended to run every minute via a cron job. However, after implementing the cron job, the service is restarted even when it is functioning correctly, causing unnecessary downtime. The administrator reviews the script and finds the following logic:
#!/bin/bash SERVICE="myapp" COUNT_FILE="/tmp/${SERVICE}_failcount"
if curl -f http://localhost:8080/health; then
echo 0 > "$COUNT_FILE" else FAILS=$(cat "$COUNT_FILE" 2>/dev/null || echo 0) FAILS=$((FAILS + 1)) echo "$FAILS" > "$COUNT_FILE"
if [ "$FAILS" -ge 3 ]; then
systemctl restart "$SERVICE" echo 0 > "$COUNT_FILE" fi fi
What is the most likely cause of the false restarts?
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
List block devices
List open files
Manage partition tables
Inform OS of partition changes
Display block device attributes
Drag a concept onto its matching description — or click a concept then click the description.
Hangup, often reload config
Interrupt from keyboard (Ctrl+C)
Force kill (cannot be caught)
Terminate gracefully
Stop/pause process (cannot be caught)
Mar 10 08:15:22 host dockerd[1234]: Time=2025-03-10T08:15:22.123Z Level=error msg="failed to mount local volume: mount :/var/lib/docker/volumes/vol1/_data:/data, flags: 0x1000: permission denied" Mar 10 08:15:22 host dockerd[1234]: Time=2025-03-10T08:15:22.124Z Level=error msg="error while mounting volume: permission denied"
[Unit] Description=My Service After=network.target [Service] ExecStart=/usr/local/bin/myservice.sh Restart=always User=nobody [Install] WantedBy=multi-user.target
$ crontab -l 0 2 * * * /usr/local/bin/cleanup.sh
Refer to the exhibit. ``` [Unit] Description=Daily Backup Service Requires=network-online.target [Service] Type=oneshot ExecStart=/usr/local/bin/backup.sh [Install] WantedBy=multi-user.target ```
Refer to the exhibit.
```
$ cat /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"storage-driver": "overlay2",
"insecure-registries": ["192.168.1.100:5000"]
}
```Refer to the exhibit. Exhibit: $ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1b2c3d4e5f6 docker.io/library/nginx:latest nginx -g 'daemon of… 2 hours ago Up 2 hours (unhealthy) 0.0.0.0:80->80/tcp web1 f6e5d4c3b2a1 docker.io/library/nginx:latest nginx -g 'daemon of… 3 hours ago Exited (0) 3 hours ago web2
Refer to the exhibit.
Exhibit:
#!/bin/bash
# Script to backup /var/www
tar -czf /backup/www-$(date +%F).tar.gz /var/www
if [ &? -eq 0 ]; then
echo "Backup successful"
else
echo "Backup failed"
fiRefer to the exhibit.
Exhibit:
{
"compose": {
"version": "3.8",
"services": {
"app": {
"image": "myapp:latest",
"cap_add": ["NET_ADMIN"],
"cap_drop": ["ALL"]
}
}
}
}Refer to the exhibit. FROM ubuntu:20.04 RUN apt-get update RUN apt-get install -y python3 COPY app.py /app/ CMD ["python3", "/app/app.py"]
Refer to the exhibit. #!/bin/bash # Script to print system info system_info=$(uname -a) echo "System: $system_info" exit 1
Refer to the exhibit.
$ cat config.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
resources:
requests:
memory: "256Mi"
cpu: "250m"
$ kubectl apply -f config.yaml
Error: The Pod "nginx" is invalid: spec.containers[0].resources.limits: Required value: must specify limits for cpu and memoryRefer to the exhibit. $ kubectl get pods NAME READY STATUS RESTARTS AGE webapp-6b9f5b7c8d-2x7ht 1/1 Running 0 10m webapp-6b9f5b7c8d-3y8iu 1/1 Running 0 10m db-7d4f6c8e9f-1a2b3 0/1 CrashLoopBackOff 5 15m
Feb 12 02:00:01 hostname CRON[1234]: (root) CMD (/usr/local/bin/backup.sh) -> /usr/local/bin/backup.sh: line 3: syntax error near unexpected token `fi'