### Install Grafana Plugins using CLI Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/grafana/README.md Use the Grafana CLI to list available plugins and install them on a local Grafana instance. Ensure you have the Grafana CLI installed and configured. ```bash grafana-cli plugins list-remote grafana-cli plugins install ``` -------------------------------- ### User Data for Web Server Setup Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/aws/exercises/auto_scaling_groups_basics/exercise.md This script is executed when a new EC2 instance is launched by the Auto Scaling Group. It installs and starts the Apache HTTP Server. ```bash yum install -y httpd systemctl start httpd systemctl enable httpd ``` -------------------------------- ### Convert to Multi-Stage Build Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/multi_stage_builds.md This example demonstrates converting a single-stage Dockerfile to a multi-stage build. The first stage installs build dependencies and builds the application, while the second stage copies only the built artifacts into a clean, minimal runtime image. ```docker FROM ubuntu AS builder RUN apt-get update \ && apt-get install -y curl python build-essential nodejs \ && apt-get clean -y RUN mkdir -p /my_app ADD ./config/nginx/docker.conf /etc/nginx/nginx.conf ADD ./config/nginx/k8s.conf /etc/nginx/nginx.conf.k8s ADD app/ /my_cool_app WORKDIR /my_cool_app RUN npm install -g ember-cli RUN npm install -g bower RUN apt-get update && apt-get install -y git \ && npm install \ && bower install RUN ember build — environment=prod FROM nginx COPY --from=builder /my_cool_app/dist /usr/share/nginx/html CMD [ "/root/nginx-app.sh", "nginx", "-g", "daemon off;" ] ``` -------------------------------- ### Ansible: Command-Line Execution Examples Source: https://context7.com/bregman-arie/devops-exercises/llms.txt Provides common Ansible command-line operations including running playbooks, overriding variables, listing modules, getting module details, and testing host connectivity. ```bash # Run a playbook ansible-playbook site.yml -i inventory.ini # Override a variable at runtime (highest precedence) ansible-playbook site.yml -e "whoami=toad" # List available modules ansible-doc -l # Get details on a specific module ansible-doc package # Test connectivity to all hosts ansible all -m ping -i inventory.ini ``` -------------------------------- ### EC2 User Data Script for Web Server Setup Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/aws/exercises/launch_ec2_web_instance/solution.md This script is executed when the EC2 instance starts. It updates packages, installs and starts the Apache HTTP Server (httpd), enables it to start on boot, and creates a basic index.html file. ```bash yum update -y yum install -y httpd systemctl start httpd systemctl enable httpd echo "

I made it! This is is awesome!

" > /var/www/html/index.html ``` -------------------------------- ### Example Dockerfile Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/solutions/image_layers.md A sample Dockerfile demonstrating various instructions that create layers or add metadata. ```dockerfile FROM ubuntu EXPOSE 212 ENV foo=bar WORKDIR /tmp RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024 RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024 RUN dd if=/dev/zero of=some_file bs=1024 count=0 seek=1024 ``` -------------------------------- ### Start a systemd service Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/linux/README.md Use this command to start a service managed by systemd. Replace `` with the actual service name. ```bash systemctl start ``` -------------------------------- ### Example ReplicaSet Output Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/README.md This output from 'kubectl get rs' shows a ReplicaSet named 'web' with 2 desired replicas, 2 current replicas, but 0 ready replicas. This indicates that while the Pods exist, their containers may not be running or ready. ```text NAME DESIRED CURRENT READY AGE web 2 2 0 2m23s ``` -------------------------------- ### Piping Command Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/linux/README.md Demonstrates how to use a pipe (|) to send the output of one command as input to another. This example counts the number of lines in the '/etc/services' file. ```bash cat /etc/services | wc -l ``` -------------------------------- ### HTML Content Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/solutions/containerized_web_server.md This is an example of HTML content served by the web server. ```html !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> Test Page for the HTTP Server on Red Hat Enterprise Linux ``` -------------------------------- ### Check Docker Installation Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/image_layers.md Verify if Docker is installed and running on your system using these commands. ```bash # Fedora/RHEL/CentOS rpm -qa | grep docker systemctl status docker ``` -------------------------------- ### Check Docker Installation Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/run_forest_run.md Verify Docker installation and status on Fedora/RHEL/CentOS systems. ```bash # Fedora/RHEL/CentOS ``` ```bash rpm -qa | grep docker ``` ```bash systemctl status docker ``` -------------------------------- ### Full Jenkins Declarative Pipeline Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/cicd/README.md A complete Jenkins declarative pipeline demonstrating agent configuration, parameters, and stages with conditional execution logic for starting from a specific stage. ```groovy pipeline { agent any parameters { string(name: 'START_STAGE', defaultValue: '', description: 'The name of the stage to start the build from') } stages { stage('Build') { // Build steps go here } stage('Test') { // Test steps go here } stage('Deploy') { // Deploy steps go here } } } ``` -------------------------------- ### Flask App Output Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/flask_container_ci2/README.md Example JSON response from the Flask application when accessing the root URI. ```json { "current_uri": "/", "example": "/matrix/\''123n456n789'\''", "resources": { "column": "/columns//", "matrix": "/matrix/", "row": "/rows//" } } ``` -------------------------------- ### Helm Values File Example Source: https://context7.com/bregman-arie/devops-exercises/llms.txt An example of a values.yaml file used with Helm to define values that can be substituted into Helm templates. ```yaml # values.yaml name: some-app container: name: some-app-container image: some-app-image:1.0 port: 8080 ``` -------------------------------- ### Test and Lint Terraform Modules Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/README.md Demonstrates commands for initializing, validating, planning, and linting a Terraform module using its examples. ```bash terraform -chdir=examples/vpc init terraform -chdir=examples/vpc validate terraform -chdir=examples/vpc plan tflint --module ``` -------------------------------- ### Consume Versioned Module from VCS Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/README.md Example of how to declare and configure a module, specifying its source (Git repository) and version. ```hcl module "vpc" { source = "git::https://github.com/org/infra-modules.git//vpc?ref=v1.2.3" cidr = "10.0.0.0/16" azs = ["us-east-1a", "us-east-1b"] } ``` -------------------------------- ### Run a container Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/README.md Use this command to start a new container from an image. The container will exit once the command finishes. ```bash podman run ubuntu ``` -------------------------------- ### Prometheus Query Examples (PromQL) Source: https://context7.com/bregman-arie/devops-exercises/llms.txt Examples of PromQL queries for monitoring container CPU, memory, HTTP errors, pod status, and node disk usage. ```promql # CPU usage rate (5-minute window) per container rate(container_cpu_usage_seconds_total[5m]) ``` ```promql # Memory usage above 90% of limit (container_memory_usage_bytes / container_spec_memory_limit_bytes) > 0.9 ``` ```promql # HTTP error rate (5xx) over last 5 minutes rate(http_requests_total{status=~"5.."}[5m]) ``` ```promql # Count of pods not in Running state per namespace count by (namespace) (kube_pod_status_phase{phase!="Running"}) ``` ```promql # Node disk usage above 80% (node_filesystem_size_bytes - node_filesystem_free_bytes) / node_filesystem_size_bytes > 0.8 ``` -------------------------------- ### Install EFS Utilities on EC2 Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/aws/exercises/create_efs/solution.md Installs the necessary utilities to mount EFS on your EC2 instances. Run this command on each instance that needs to access the EFS. ```bash sudo yum install -y amazon-efs-utils ``` -------------------------------- ### Argo Rollouts AnalysisTemplate Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/argo/README.md Defines an AnalysisTemplate resource for Argo Rollouts. This example configures a success rate metric using Prometheus, specifying conditions for continuing or rolling back a deployment based on the observed success rate. ```yaml apiVersion: argoproj.io/v1alpha1 kind: AnalysisTemplate metadata: name: success-rate spec: args: - name: service-name metrics: - name: success-rate interval: 4m count: 3 successCondition: result[0] >= 0.90 provider: prometheus: address: http:/some-prometheus-instance:80 query: sum(response_status{app="{{args.service-name}}",role="canary",status=~"2.*"})/sum(response_status{app="{{args.service-name}}",role="canary"} ``` -------------------------------- ### Install Argo Rollouts Controller Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/argo/exercises/blue_green_rollout/solution.md Installs the Argo Rollouts controller into the specified Kubernetes namespace. Ensure the namespace exists before applying. ```bash kubectl create namespace argo-rollouts ``` ```bash kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml ``` -------------------------------- ### Install Grafana Plugins from Archive Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/grafana/README.md Install a Grafana plugin by downloading a packaged archive and extracting it into the Grafana plugin directory. Verify the plugin directory path in your Grafana configuration. ```bash unzip my-plugin-0.2.0.zip -d YOUR_PLUGIN_DIR/my-plugin ``` -------------------------------- ### Run Nginx Container Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/solutions/running_containers.md Starts a new container using the latest nginx image. Ensure you have nginx:latest available. ```bash podman container run nginx:latest ``` -------------------------------- ### Join Customers and Orders Tables Source: https://github.com/bregman-arie/devops-exercises/blob/master/README.md Demonstrates the concept of joining tables on a common key. The example explains that Customer_ID is the unique key for both tables. ```sql You would join them on the unique key. In this case, the unique key is Customer_ID in both the Customers table and Orders table ``` -------------------------------- ### Terraform File Structure Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/README.md Standard Terraform project files include main.tf, providers.tf, outputs.tf, variables.tf, and dependencies.tf. These can be further divided for maintainability. ```terraform main.tf providers.tf outputs.tf variables.tf dependencies.tf ``` -------------------------------- ### Create Dockerfile for Node.js App Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/devops/solutions/containerize_app.md Defines the steps to build a Docker image for a Node.js application. Installs dependencies and sets the entrypoint. ```dockerfile FROM alpine LABEL maintainer="your name/email" RUN apk add --update nodejs npm COPY . /src WORKDIR /src RUN npm install EXPOSE 3000 ENTRYPOINT ["node", "./app.js"] ``` -------------------------------- ### Manage Argo CD Application State via CLI Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/argo/exercises/app_creation/solution.md These commands are used to list all applications, get detailed information about a specific application, synchronize its state with the repository, and wait for the synchronization to complete. Use `argocd app list` to see all apps, `argocd app get ` for details, `argocd app sync ` to trigger a sync, and `argocd app wait ` to pause until sync is done. ```bash # Check app state argocd app list argocd app get app-demo ``` ```bash # Sync app state argocd app sync app-demo argocd app wait app-demo ``` -------------------------------- ### Run a Pod with httpd Image Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/solutions/killing_containers.md Starts a new pod named 'web' using the httpd image. This is the initial step to have a running service to experiment with. ```bash kubectl run web --image registry.redhat.io/rhscl/httpd-24-rhel7 ``` -------------------------------- ### Enable Service Auto-start with System V Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/linux/README.md For System V init systems, use 'update-rc.d' to manage service startup. Additionally, configure '/etc/inittab' for services requiring respawn functionality. ```bash update-rc.d [service_name] ``` ```bash id:5678:respawn:/bin/sh /path/to/app ``` -------------------------------- ### Print Linux Users Starting with 'd' or 'D' using Perl Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/perl/README.md Print all system users from '/etc/passwd' whose usernames start with 'd' or 'D'. This example shows both a one-liner approach and a more verbose loop. ```perl open(my $fh, '<', '/etc/passwd'); my @user_info = <$fh>; map { print $& . "\n" if $_ =~ /^d([^:]*)/ } @user_info; close $fh; ``` ```perl foreach my $user_line (@user_info) { if ($user_line =~ /^d([^:]*)/) { print $& . "\n"; } } ``` -------------------------------- ### Initialize Repository and Make First Commit Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/git/solutions/commit_01_solution.md This sequence of commands initializes a new Git repository, creates a file, stages it, and then commits it with a message. Use this to understand the fundamental Git workflow for a new project. ```bash mkdir my_repo && cd my_repo git init echo "hello_commit" > file git add file git commit -a -m "It's my first commit. Exciting!" git log ``` -------------------------------- ### Use Terraform Data Source to Get AWS VPC Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/README.md Example of using a data source to retrieve information about the default AWS VPC. Data sources are used for reading existing infrastructure. ```terraform data "aws_vpc" "default { default = true } ``` -------------------------------- ### Create New Files Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/linux/README.md Demonstrates methods for creating new files: an empty file with `touch`, a file with content using `cat` and redirection, and a file of a specific size with `truncate`. ```bash touch new_file.txt ``` ```bash cat > new_file.txt submit text; ctrl + d to exit insert mode ``` ```bash truncate -s new_file.txt ``` -------------------------------- ### Helm Template Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/README.md Demonstrates a basic Helm template file for a Kubernetes Pod, showing how to use placeholders for dynamic values. The corresponding values file defines the actual data for these placeholders. ```yaml apiVersion: v1 kind: Pod metadata: name: {[ .Values.name ]} spec: containers: - name: {{ .Values.container.name }} image: {{ .Values.container.image }} port: {{ .Values.container.port }} ``` ```yaml name: some-app container: name: some-app-container image: some-app-image port: 1991 ``` -------------------------------- ### Create Pod and Expose Service in One Command Source: https://context7.com/bregman-arie/devops-exercises/llms.txt Creates a pod using a specified image and immediately exposes it via a service on a given port. This is a shortcut for simple deployments. ```bash kubectl run nginx --image=nginx --restart=Never --port 80 --expose ``` -------------------------------- ### Set up Persistent Storage for MySQL Container Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/solutions/containerized_db_persistent_storage.md Prepare a host directory for database storage and configure SELinux contexts. Then, run a MySQL container, mounting the host directory to persist database files. ```bash # Create the directory for the DB on host mkdir -pv ~/local/mysql sudo semanage fcontext -a -t container_file_t '/home/USERNAME/local/mysql(/.*)?' sudo restorecon -R /home/USERNAME/local/mysql # Run the container podman run --name mysql -e MYSQL_USER=mario -e MYSQL_PASSWORD=tooManyMushrooms -e MYSQL_DATABASE=university -e MYSQL_ROOT_PASSWORD=MushroomsPizza -d mysql -v /home/USERNAME/local/mysql:/var/lib/mysql/db # Verify it's running podman ps ``` -------------------------------- ### Helm Template Example with Values Substitution Source: https://context7.com/bregman-arie/devops-exercises/llms.txt A Helm template file (e.g., templates/deployment.yaml) demonstrating how to use values from a values.yaml file for dynamic configuration. ```yaml apiVersion: v1 kind: Pod metadata: name: {{ .Values.name }} spec: containers: - name: {{ .Values.container.name }} image: {{ .Values.container.image }} ports: - containerPort: {{ .Values.container.port }} ``` -------------------------------- ### Create main.tf File Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/exercises/vpc_subnet_creation/solution.md Initialize the main Terraform configuration file where your VPC and subnet resources will be defined. ```bash touch main.tf ``` -------------------------------- ### Ansible Playbook: Install zlib and Create File Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/ansible/solutions/my_first_playbook.md Defines tasks to install the 'zlib' package and create an empty file at '/tmp/some_file' on specified hosts. Requires root privileges for package installation. ```yaml - name: Install zlib and create a file hosts: some_remote_host tasks: - name: Install zlib package: name: zlib state: present become: yes - name: Create the file /tmp/some_file file: path: '/tmp/some_file' state: touch ``` -------------------------------- ### Run a web server with port mapping Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/README.md Starts an HTTPD service in a container, maps port 8080 on the host to port 8080 in the container, and makes it accessible from localhost. ```bash podman run -d --name apache1 -p 8080:8080 registry.redhat.io/rhel8/httpd-24 curl 127.0.0.1:8080 ``` -------------------------------- ### Create VM Instance with Labels Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/gcp/exercises/instance_101/solution.md Create a Compute Engine VM instance named 'instance-1' with specified labels and machine type. Ensure gcloud CLI is configured for the correct project and zone. ```bash gcloud compute instances create instance-1 --labels app=web,env=dev --machine-type=e2-micro ``` -------------------------------- ### Install a Perl module with cpanm Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/perl/README.md Install the 'Test' module using the 'cpanm' command-line tool. ```bash cpanm Test ``` -------------------------------- ### Create a Static Pod Manifest Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/README.md To create a static pod, navigate to the directory specified by `staticPodPath` in the kubelet configuration (commonly `/etc/kubernetes/manifests`). Then, use `kubectl run` with `--dry-run=client -o yaml` to generate the pod definition file. ```bash cd /etc/kubernetes/manifests k run some-pod --image=python --command sleep 2017 --restart=Never --dry-run=client -o yaml > statuc-pod.yaml ``` -------------------------------- ### Check Docker Installation and Status Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/solutions/run_forest_run.md Verify Docker is installed and running on your system. These commands are for Fedora/RHEL/CentOS. ```bash # Fedora/RHEL/CentOS rpm -qa | grep docker systemctl status docker ``` -------------------------------- ### Install a Terraform Provider Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/README.md Configure and install a specific Terraform provider, such as the AWS provider, by defining its block and running `terraform init`. ```terraform provider "aws" { region = "us-west-1" } ``` -------------------------------- ### List storage buckets using gsutil Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/gcp/README.md List all available storage buckets using the gsutil command-line tool. ```bash gsutil ls ``` -------------------------------- ### Install cpanm using cpan Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/perl/README.md Use the 'cpan' command to install the 'App::cpanminus' module, which is a tool for managing Perl modules. ```bash $ cpan App::cpanminus ``` -------------------------------- ### Core Git Workflow: Initialization, Staging, and Committing Source: https://context7.com/bregman-arie/devops-exercises/llms.txt Basic Git commands to initialize a repository, check status, stage changes, and commit them with a message. Use `git add .` to stage all changes. ```bash # Initialize a repository git init my-project # Stage and commit git status git add . git commit -m "Initial commit" ``` -------------------------------- ### Namespace-Scoped ConfigMap Example Source: https://context7.com/bregman-arie/devops-exercises/llms.txt An example of a Kubernetes ConfigMap resource defined with a specific namespace. This allows configuration to be isolated within a namespace. ```yaml apiVersion: v1 kind: ConfigMap metadata: name: app-config namespace: dev data: db_url: postgres.dev.svc.cluster.local ``` -------------------------------- ### Create a Deployment with kubectl Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/README.md Use this command to quickly create a new deployment with a specified image. ```bash kubectl create deployment my-first-deployment --image=nginx:alpine ``` -------------------------------- ### Create and Copy HTML File Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/solutions/commit_image.md Creates a simple HTML file named 'index.html' with custom content and then copies it into the running 'nginx_container' to the web server's document root. ```bash # Create index.html file cat <>index.html It's a me

Mario

EOT # Copy index.html to the container podman cp index.html nginx_container:/usr/share/nginx/html/index.html ``` -------------------------------- ### Start Docker Compose Services Source: https://github.com/bregman-arie/devops-exercises/blob/master/exercises/docker/docker-debugging.md Start all services defined in a `docker-compose.yml` file in detached mode. This command manages the network and dependencies between containers. ```bash docker-compose up -d ``` -------------------------------- ### Deploy a Pod using kubectl Source: https://github.com/bregman-arie/devops-exercises/blob/master/certificates/cka.md Use `kubectl run` to deploy a pod with a specified image and restart policy. Ensure the image is available in your container registry. ```bash kubectl run web-1985 --image=nginx:alpine --restart=Never ``` -------------------------------- ### View All Nodes Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/CKA.md List all nodes in the Kubernetes cluster using `kubectl get nodes`. An alias `k=kubectl` is recommended for brevity, allowing `k get no`. ```bash kubectl get nodes ``` -------------------------------- ### Create and Edit a Pod to Test Taints Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/exercises/taints_101/solution.md This snippet demonstrates creating a basic pod and then editing its configuration. This is useful for testing how pods interact with node taints. ```bash kubectl run some-pod --image=redis kubectl edit po some-pod ``` -------------------------------- ### Conditional Package Installation Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/ansible/README.md Installs 'zlib' and 'vim' on all hosts only if the file '/tmp/mario' exists on the system. Uses the 'stat' module to check for file existence and registers the result. ```yaml --- - hosts: all vars: mario_file: /tmp/mario package_list: - 'zlib' - 'vim' tasks: - name: Check for mario file stat: path: "{{ mario_file }}" register: mario_f - name: Install zlib and vim if mario file exists become: "yes" package: name: "{{ item }}" state: present with_items: "{{ package_list }}" when: mario_f.stat.exists ``` -------------------------------- ### Create a Namespace Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/CKA.md Create a new namespace with the specified name using `k create ns NAMESPACE_NAME`. ```bash k create ns alle ``` -------------------------------- ### Go Min-Heap Implementation and Usage Source: https://github.com/bregman-arie/devops-exercises/blob/master/README.md This Go code defines a min-heap for integers and demonstrates its initialization, pushing elements, and accessing the minimum element. Ensure the `container/heap` package is imported. ```go package main import ( "container/heap" "fmt" ) // An IntHeap is a min-heap of ints. type IntHeap []int func (h IntHeap) Len() int { return len(h) } func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] } func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h *IntHeap) Push(x interface{}) { // Push and Pop use pointer receivers because they modify the slice's length, // not just its contents. *h = append(*h, x.(int)) } func (h *IntHeap) Pop() interface{} { old := *h n := len(old) x := old[n-1] *h = old[0 : n-1] return x } func main() { h := &IntHeap{4, 8, 3, 6} heap.Init(h) heap.Push(h, 7) fmt.Println((*h)[0]) } ``` -------------------------------- ### Perl POD Documentation Example Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/perl/README.md Example of using Perl's Plain Old Documentation (POD) format to document a subroutine. POD is a markup language for documenting Perl code. ```perl =item This function returns the factorial of a number. Input: $n (number you wanna calculate). Output: number factorial. =cut sub factorial { my ($i, $result, $n) = (1, 1, shift); $result = $result *= $i && $i++ while $i <= $n; return $result; } ``` -------------------------------- ### Node.js package.json start script Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/aws/exercises/elastic_beanstalk_simple/solution.md Ensure your Node.js application's package.json file includes a 'start' script that defines how to run the application. This is crucial for Elastic Beanstalk to launch your service. ```json { "name": "application-name", "version": "0.0.1", "private": true, "scripts": { "start": "node app" }, "dependencies": { "express": "3.1.0", "jade": "*", "mysql": "*", "async": "*", "node-uuid": "*" } } ``` -------------------------------- ### Initialize Terraform Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/terraform/exercises/vpc_subnet_creation/solution.md Run this command to download the necessary AWS provider plugin for Terraform to manage your AWS resources. ```bash terraform init ``` -------------------------------- ### Helm Install with Override Values Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/README.md Shows how to install a Helm chart while overriding default values. This can be done by providing an alternative values file or by specifying individual key-value pairs directly on the command line. ```bash helm install --values=override-values.yaml [CHART_NAME] ``` ```bash helm install --set some_key=some_value ``` -------------------------------- ### Describe ReplicaSet to Verify New Pod Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/solutions/replicaset_03_solution.md Use 'kubectl describe rs web' to inspect the ReplicaSet named 'web'. This command provides detailed information, including events and the current state, which will confirm that a new Pod has been created by the ReplicaSet to compensate for the removed label. ```bash kubectl describe rs web ``` -------------------------------- ### Verify ReplicaSet Creation Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/solutions/replicaset_03_solution.md Check if the ReplicaSet has been successfully created and if it has the expected number of replicas. You can use 'kubectl get rs' for a general overview or 'kubectl get -f rs.yaml' for a more specific check against the applied file. ```bash kubectl get rs ``` ```bash # OR a more specific way: kubectl get -f rs.yaml ``` -------------------------------- ### Get Pod Information including Node Source: https://github.com/bregman-arie/devops-exercises/blob/master/certificates/cka.md Use `kubectl get po -o wide` to display detailed pod information, including the node on which each pod is scheduled. This is useful for troubleshooting and understanding pod placement. ```bash kubectl get po -o wide ``` -------------------------------- ### Ansible: Conditional Package Install and Template Deploy Source: https://context7.com/bregman-arie/devops-exercises/llms.txt This playbook installs packages conditionally based on a file's existence and deploys a system info template. Ensure the 'system_info.j2' template file is available in the correct path. ```yaml - name: Deploy system info and install packages conditionally hosts: all:!controllers vars: mario_file: /tmp/mario package_list: - zlib - vim tasks: - name: Check for mario file stat: path: "{{ mario_file }}" register: mario_f - name: Install packages if mario file exists become: yes package: name: "{{ item }}" state: present with_items: "{{ package_list }}" when: mario_f.stat.exists - name: Deploy system_info from template template: src: system_info.j2 dest: /tmp/system_info ``` ```yaml # system_info.j2 template # {{ ansible_managed }} I'm {{ ansible_hostname }} and my operating system is {{ ansible_distribution }} ``` -------------------------------- ### View Docker Image Build History Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/containers/README.md Display the instructions used to build a specific container image. This helps in understanding the image's construction. ```bash docker image history : ``` -------------------------------- ### Create Deployment with Replicas Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/CKA.md Create a Kubernetes deployment named 'pluck' using the 'redis' image and ensuring it runs 5 replicas. ```bash kubectl create deployment pluck --image=redis --replicas=5 ``` -------------------------------- ### Get Services Source: https://github.com/bregman-arie/devops-exercises/blob/master/topics/kubernetes/README.md Check if a service has been created by listing all services in the cluster. ```bash kubectl get svc ```