DevOps Roadmap – 2019


Road to become a DevOps Engineer

devops.png

 

source: https://github.com/kamranahmedse/developer-roadmap#devops-roadmap

Build Automation Gradle Interview Questions


What does the command ./gradlew do when it is run from within a Gradle project’s directory?
– It runs the Gradle Wrapper.

What does a smoke test do?
– Tests large-scale, basic things like whether or not the application runs.

What can you use to take advantage of pre-built Gradle tasks created by the Gradle community?
– Gradle plugins

Which of the following are the kinds of tasks build automation tools usually handle? (Choose all that apply)

– Compiling code
– Packaging the app for deployment
– Dependency management

What does Gradle do?
– Build Automation

Which type of testing tests the smallest amount of code in a single test?
– Unit test

Which of the following does declaring a dependency between two tasks in Gradle do? (Choose all that apply)

– It ensures that when a task is called, the task that it depends on also runs.
– It ensures that if both tasks are run, the task which is a dependency will always run before the one that depends on it.
What software does Gradle require to be installed on a system before it can run?
– Java JDK 7 or higher

What does build automation do?
– It automates the process of processing source code in preparation for deployment.

Terraform Interview Questions


You are testing out a new environment and need to ensure you are using the right syntax to reference resources. What are two commands that can help you discover and test the correct interpolation syntax?

– terraform console
– terraform show
How would name a Docker image resource for reference later?

– resources “docker_image”
How do you specify the location of the module you are referencing in the root/main.tf file?

– source = “./modulename”
You need to deploy a development and a production environment simultaneously on the same machine. What feature of Terraform allows you to deploy multiple environments with independent states?

– workspace

You are writing a Terraform script to deploy Docker containers for your organization. You have several items to deploy, what word does Terraform use to refer to each item it deploys?

– Resources
If you change the port of a Docker container in your Terraform script and run a “terraform apply”, what will happen to your deployment?

– The old resource is destroyed and the new one takes its place.
You are referencing infrastructure in an output file. In this resource: “resource “docker_image” “ghost””, which string is the resource ID?

– ghost
You need to be able to specify different variable definitions based on whether the environment is a production or development area. What type of variables rely on key-value pairs in order to be defined dynamically based on other provided information?

– Maps

You are trying to search your system for the file that contains all of your variable definitions. The previous admin has lost it. What extension does the file that holds your variable definitions have?

– .tfvars

Which of the following is an accurate use description for Terraform?

– Terraform is used for building, changing, and versioning infrastructure with safely and efficiently.

You need to output the IP address of your docker container with ID “container_id” in order to provide access to your coworkers. How would you script this output value?

– value = “${docker_container.container_id.ip_address}”

Which provisioner should you use to run a command on the Terraform server during deployment?

– local-exec

At your company, you need to provide a deployment with variables that are defined interactively when applying. For the “image” variable, you want to ensure the user knows this refers to the name of the image. How would you word this in your variable block?

– description = “name of the image”

You are trying to decide how to define your variables. What are three common files in which you can specify the value of a variable without having to use a function to extract them? (Choose all that apply)

– variables.tf
– main.tf
– terraform.tfvars

You have a variable that changes often and you want the ability to modify it during your Terraform apply, either via an external file or by entering it interactively. How should this variable be expressed in the variables.tf file?

– variable “image” {}

The best place to learn Terraform is :Linux Academy

When should you use Lambda over EC2?


– Changes to Amazon S3 Buckets
– Updates to an Amazon DynamoDb tables
– Custom events generated bu your application or devices
– Kinesis Streams

Monitoring in Kubernetes with Prometheus and Grafana


My team is building the new severless web application. They currently have it running on a Kubernetes cluster, but they need to monitor the performance of the cluster and the applications running on it. My task is to install and setup up Prometheus to aggregate data and Grafana to display this data. Both can be installed on the Kubernetes cluster itself. To make sure everything is working, you will need to create two dashboards in Grafana:

  1. Import the Kubernetes All Nodes community dashboard to display basic metrics about the Kubernetes cluster.
  2. Create a new Dashboard and add a graph showing requests per minute for the train-schedule app.

You need to setup two server 

1. Kubernetes Master
2. Kubernetes Node
Steps to Follow:

1. Login into Kubernetes Master Server

kubectl-get-node

kubectl get nodes

2. Initialize helm with: helm init --wait

cloud_user@ip-10-0-1-101:~$ helm init –wait
Creating /home/cloud_user/.helm
Creating /home/cloud_user/.helm/repository
Creating /home/cloud_user/.helm/repository/cache
Creating /home/cloud_user/.helm/repository/local
Creating /home/cloud_user/.helm/plugins
Creating /home/cloud_user/.helm/starters
Creating /home/cloud_user/.helm/cache/archive
Creating /home/cloud_user/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /home/cloud_user/.helm.

3. Now you can use HELM to install Prometheus and Grafana. I am going to use the charts provided by Kubernetes. You can get these from https://github.com/kubernetes/charts

git clone https://github.com/kubernetes/charts
cd charts
git checkout efdcffe0b6973111ec6e5e83136ea74cdbe6527d
cd ../

cloud_user@ip-10-0-1-101:~$ git clone https://github.com/kubernetes/charts
Cloning into ‘charts’…
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 41509 (delta 0), reused 1 (delta 0), pack-reused 41502
Receiving objects: 100% (41509/41509), 13.04 MiB | 25.28 MiB/s, done.
Resolving deltas: 100% (27058/27058), done.
Checking connectivity… done.
cloud_user@ip-10-0-1-101:~$ cd charts
cloud_user@ip-10-0-1-101:~/charts$ git checkout efdcffe0b6973111ec6e5e83136ea74cdbe6527d
Note: checking out ‘efdcffe0b6973111ec6e5e83136ea74cdbe6527d’.

You are in ‘detached HEAD’ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b

HEAD is now at efdcffe… [stable/prometheus] Ability to enable admin API (#5570)
cloud_user@ip-10-0-1-101:~/charts$ cd ../

4. Create a prometheus-values.yml for prometheus to turn off persistent storage:

cloud_user@ip-10-0-1-101:~$ vi prometheus-values.yml
lertmanager:
  persistentVolume:
      enabled: false
server:
  persistentVolume:
      enabled: false
5. Use helm to install prometheus in the prometheus namespace: cloud_user@ip-10-0-1-101:~$ vi prometheus-values.yml cloud_user@ip-10-0-1-101:~$ helm install -f ~/prometheus-values.yml ~/charts/stable/prometheus --name prometheus --namespace prometheus NAME: prometheus LAST DEPLOYED: Mon Oct 8 19:49:37 2018 NAMESPACE: prometheus STATUS: DEPLOYED RESOURCES: ==> v1/ServiceAccount NAME SECRETS AGE prometheus-alertmanager 1 2s prometheus-kube-state-metrics 1 2s prometheus-node-exporter 1 2s prometheus-pushgateway 1 2s prometheus-server 1 2s ==> v1/ConfigMap NAME DATA AGE prometheus-alertmanager 1 2s prometheus-server 3 2s ==> v1beta1/ClusterRole NAME AGE prometheus-kube-state-metrics 2s prometheus-server 2s ==> v1beta1/ClusterRoleBinding NAME AGE prometheus-kube-state-metrics 2s prometheus-server 2s ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE prometheus-alertmanager ClusterIP 10.111.155.200 80/TCP 1s prometheus-kube-state-metrics ClusterIP None 80/TCP 1s prometheus-node-exporter ClusterIP None 9100/TCP 1s prometheus-pushgateway ClusterIP 10.101.32.144 9091/TCP 1s prometheus-server ClusterIP 10.106.116.125 80/TCP 1s ==> v1beta1/DaemonSet NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE prometheus-node-exporter 1 1 0 1 0 1s ==> v1beta1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE prometheus-alertmanager 1 1 1 0 1s prometheus-kube-state-metrics 1 1 1 0 1s prometheus-pushgateway 1 1 1 0 1s prometheus-server 1 1 1 0 1s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE prometheus-node-exporter-rpdkx 0/1 ContainerCreating 0 1s prometheus-alertmanager-6df98765f4-vml9x 0/2 Pending 0 1s prometheus-kube-state-metrics-6584885ccf-4zxrl 0/1 ContainerCreating 0 1s prometheus-pushgateway-66c9fdb48f-2znbs 0/1 ContainerCreating 0 1s prometheus-server-65d5cc8544-jwwvr 0/2 Init:0/1 0 1s ==> v1/PersistentVolumeClaim NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE prometheus-alertmanager Pending 2s NOTES: The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster: prometheus-server.prometheus.svc.cluster.local Get the Prometheus server URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace prometheus port-forward $POD_NAME 9090 ################################################################################# ###### WARNING: Persistence is disabled!!! You will lose your data when ##### ###### the Server pod is terminated. ##### ################################################################################# The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster: prometheus-alertmanager.prometheus.svc.cluster.local Get the Alertmanager URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace prometheus port-forward $POD_NAME 9093 The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster: prometheus-pushgateway.prometheus.svc.cluster.local Get the PushGateway URL by running these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace prometheus port-forward $POD_NAME 9091 For more information on running Prometheus, visit: https://prometheus.io/

6. Create a grafana-values.yml for grafana to set an admin password:

cloud_user@ip-10-0-1-101:~$ vi grafana-values.yml
adminPassword: password

7. Use helm to install grafana in the grafana namespace:

helm install -f ~/grafana-values.yml ~/charts/stable/grafana –name grafana –namespace grafan

Deploy a NodePort service to provide external access to grafana. Make a file called grafana-ext.yml:

grafana-ext.yml

And deploy the service:   kubectl apply -f ~/grafana-ext.yml