Skip to main content
In this guide, we walk through the solutions for Lightning Lab 1 step by step. Each task includes detailed configuration files and commands to accomplish the requirements effectively.

Task 1: Create a Persistent Volume

The first task is to create a persistent volume named log-volume with the following specifications:
  • Storage Class: manual
  • Access Mode: ReadWriteMany (RWX)
  • Capacity: 1Gi
  • Host Path: /opt/volume/nginx
A common starting point is referencing the Kubernetes documentation. Here’s an example snippet that you might have encountered:
Adjust this example to match our requirements. The complete persistent volume configuration becomes:
Apply the configuration:
Then verify the persistent volume is created:

Task 2: Create a Persistent Volume Claim

Next, create a persistent volume claim (PVC) named log-claim with these requirements:
  • Access Mode: ReadWriteMany
  • Storage Request: 8Gi of storage
  • Storage Class: manual
Use the following YAML configuration:
Save this as log-claim.yaml and apply it:
After applying, check the PVC status:

Task 3: Mount the Volume in a Pod

Now, mount the PVC into a pod named logger at the mount path /var/www/nginx. This pod will run a container using the nginx:alpine image.

Step 1: Generate the Initial Pod YAML

Create the pod configuration using a dry-run:

Step 2: Edit the YAML to Add Volumes and Volume Mounts

Modify logger.yaml to include:
  • A volumes section to reference the PVC.
  • A volumeMounts section under the container to specify the mount path.
Place the following snippet under the spec:
And under the container definition, add:
After ensuring the field name is correctly spelled (persistentVolumeClaim with an “s”), apply the updated configuration:
If you encounter an error like:
Ensure that the field name persistentVolumeClaim is spelled correctly and that you have saved the file appropriately before re-applying.
Verify the pod creation:

Task 4: Troubleshoot Network Connectivity for Secure Pod

A pod named secure-pod and a service named secure-service are deployed. However, incoming and outgoing connections to the secure pod are currently failing, and traffic from the webapp-color pod using secure-service is not working.

Step 1: Verify Pods and Service

Check the pods:
Expected output:
Check the service:
Expected output:

Step 2: Test Connectivity from the webapp-color Pod

Enter the pod shell:
Inside the pod, test connectivity with netcat:
A timeout error confirms the issue.

Step 3: Check the Existing Network Policy

Run:
The output will reveal that a default deny policy is in effect.

Step 4: Identify Pod Labels

Determine the pod labels with:
Example output:

Step 5: Create a Network Policy

Create a network policy YAML (netpol.yaml) to allow ingress traffic from pods labeled name=webapp-color to the pod labeled run=secure-pod on port 80:
Apply the policy:

Step 6: Retest Connectivity

From the webapp-color pod, execute:
A successful connection message confirms that the issue has been resolved.

Task 5: Create a Time-Check Pod Using a ConfigMap

In this task, we create a pod that periodically checks the system time. This pod is deployed in a new namespace (for example, dv11987).

Step 1: Create the Namespace

If the namespace doesn’t already exist, create it:

Step 2: Create the ConfigMap

Create a ConfigMap named time-config with the key-value pair TIME_FREQ=10:
Verify the ConfigMap:

Step 3: Generate the Pod YAML

Generate a pod configuration for time-check using the busybox image:

Step 4: Edit the Pod Configuration

Update time-check.yaml to include the environment variable from the ConfigMap, a command that logs the current date, and a volume mounted at /opt/time using emptyDir:
Apply the configuration:
Verify the pod is running in the dv11987 namespace:
If you have any pods with conflicting names in the default namespace, delete them before applying the new configuration.

Task 6: Create and Upgrade an Nginx Deployment

Create a deployment named nginx-deploy with the following requirements:
  • Image: nginx:1.16 initially
  • Replicas: 4
  • Rolling Update Strategy:
    • maxSurge: 1
    • maxUnavailable: 2

Step 1: Generate the Deployment YAML

Generate the deployment using a dry-run:

Step 2: Edit the Deployment for Rolling Updates

Modify nginx-deploy.yaml to add the rolling update strategy:
Apply the deployment:

Step 3: Upgrade the Deployment

Upgrade the deployment to use nginx:1.17:
Monitor the rollout:

Step 4: Rollback the Deployment

After the upgrade, rollback to the previous version if needed:

Task 7: Create a Redis Deployment with Resource Limits and Volume Mounts

Finally, create a deployment named redis with these parameters:
  • Image: redis:alpine
  • Replicas: 1
  • Resource Request: 0.2 CPU
  • Label: app=redis
  • Volumes:
    • data: Use emptyDir mounted at /redis-master-data
    • redis-config: Use a ConfigMap (named redis-config) mounted at /redis-master
  • Exposed Port: 6379

Step 1: Generate the Deployment YAML

Generate the initial deployment:

Step 2: Edit the Deployment File

Update redis.yaml with the correct resource requests, volumes, and volume mounts:
Apply the deployment:

After completing all the tasks, validate your configurations with the appropriate kubectl get commands to ensure that all pods, deployments, and services are running as expected. Happy deploying!

Watch Video

Practice Lab