Kodekloud Terraform Challenge 1 solution | Install , Configure terraform and provider settings within provider.tf | Deploy several Kubernetes resources using terraform

Ticker

6/recent/ticker-posts

Kodekloud Terraform Challenge 1 solution | Install , Configure terraform and provider settings within provider.tf | Deploy several Kubernetes resources using terraform

Question : Welcome to the terraform challenge series.

In this challenge we will deploy several Kubernetes resources using terraform.
Utilize /root/terraform_challenge directory to store your Terraform configuration files.

Inspect the requirements in detail by clicking on the icons of the interactive architecture diagram on the right and complete the tasks.

1. Terraform version: 1.1.5 installed on controlplane?

2.  Kubernetes provider : - 

  • Configure terraform and provider settings within provider.tf file with following specifications:
  • Configure terraform to use hashicorp/kubernetes provider.
  • Specify the provider's local name: kubernetes
  • Provider version: 2.11.0
  • Configure kubernetes provider with path to your kubeconfig file: /root/.kube/config

3.  Create a terraform resource webapp-service for kubernetes service with following specs:

  • Service name: webapp-service
  • Service Type: NodePort
  • Port: 8080
  • NodePort: 30080
4. Create a terraform resource frontend for kubernetes deployment with following specs:

  • Deployment Name: frontend
  • Deployment Labels = name: frontend
  • Replicas: 4
  • Pod Labels = name: webapp
  • Image: kodekloud/webapp-color:v1
  • Container name: simple-webapp
  • Container port: 8080


Solution:  

1. Prerequisite  for this task  is to update packages & Install unzip package

root@controlplane ~   cat /etc/os-release

NAME="Ubuntu"

VERSION="18.04.6 LTS (Bionic Beaver)"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu 18.04.6 LTS"

VERSION_ID="18.04"

HOME_URL="https://www.ubuntu.com/"

SUPPORT_URL="https://help.ubuntu.com/"

BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"

PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"

VERSION_CODENAME=bionic

UBUNTU_CODENAME=bionic

root@controlplane ~  

root@controlplane ~ which unzip

 root@controlplane ~ apt update

Get:2 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]                                                                  

Get:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                                                

Get:1 https://packages.cloud.google.com/apt kubernetes-xenial InRelease [8,993 B]                                      

Get:4 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]                                                                                   

Get:5 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [46.4 kB]                           

Get:6 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages [69.9 kB]  

Get:7 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]               

Get:8 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [83.3 kB]

Get:9 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [1,688 kB]

Get:10 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]

Get:11 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]             

Get:12 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [23.8 kB]   

Get:13 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,637 kB]                          

Get:14 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [3,373 kB]                              

Get:15 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1,344 kB]                                           

Get:16 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]

Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [1,728 kB]

Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [2,411 kB]

Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [3,785 kB]

Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [30.8 kB]

Get:21 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [64.0 kB]

Get:22 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [20.6 kB]

Fetched 28.3 MB in 3s (9,683 kB/s)                           

Reading package lists... Done

Building dependency tree      

Reading state information... Done

79 packages can be upgraded. Run 'apt list --upgradable' to see them.

 root@controlplane ~   apt install unzip -y

Reading package lists... Done

Building dependency tree      

Reading state information... Done

Suggested packages:

  zip

The following NEW packages will be installed:

  unzip

0 upgraded, 1 newly installed, 0 to remove and 79 not upgraded.

Need to get 168 kB of archives.

After this operation, 567 kB of additional disk space will be used.

Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 unzip amd64 6.0-21ubuntu1.2 [168 kB]

Fetched 168 kB in 0s (720 kB/s)

debconf: delaying package configuration, since apt-utils is not installed

Selecting previously unselected package unzip.

(Reading database ... 16004 files and directories currently installed.)

Preparing to unpack .../unzip_6.0-21ubuntu1.2_amd64.deb ...

Unpacking unzip (6.0-21ubuntu1.2) ...

Setting up unzip (6.0-21ubuntu1.2) ...

Processing triggers for mime-support (3.60ubuntu1) ...

Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

 root@controlplane ~   which unzip

/usr/bin/unzip

root@controlplane ~ 


2. Check Terraform version and download the ZIP file and extract it

root@controlplane ~   which terraform

root@controlplane ~  

root@controlplane ~   curl -L -o /tmp/terraform_1.1.5_linux_amd64.zip https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_linux_amd64.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100 17.8M  100 17.8M    0     0  45.9M      0 --:--:-- --:--:-- --:--:-- 45.9M

 root@controlplane ~   ls /tmp

systemd-private-bac02dd1f6b44f1ca3c0c2e17a9e6c3b-systemd-resolved.service-GujsGO  terraform_1.1.5_linux_amd64.zip

 root@controlplane ~   unzip -d /usr/local/bin /tmp/terraform_1.1.5_linux_amd64.zip

Archive:  /tmp/terraform_1.1.5_linux_amd64.zip

  inflating: /usr/local/bin/terraform 

 root@controlplane ~   which terraform

/usr/local/bin/terraform

 root@controlplane ~   terraform --version

Terraform v1.1.5

on linux_amd64

 Your version of Terraform is out of date! The latest version

is 1.6.4. You can update by downloading from https://www.terraform.io/downloads.html

root@controlplane ~


3. Configure terraform and provider settings within the provider.tf file

root@controlplane ~   cd /root/terraform_challenge/

root@controlplane ~/terraform_challenge   ls

root@controlplane ~/terraform_challenge   vi provider.tf

 root@controlplane ~/terraform_challenge via 💠 default   cat provider.tf

terraform {

  required_providers {

    kubernetes = {

      source = "hashicorp/kubernetes"

      version = "2.11.0"

    }

  }

}

 

provider "kubernetes" {

  config_path    = "/root/.kube/config"

}

root@controlplane ~/terraform_challenge via 💠 default   terraform init

Initializing the backend...

Initializing provider plugins...

- Finding hashicorp/kubernetes versions matching "2.11.0"...

- Installing hashicorp/kubernetes v2.11.0...

- Installed hashicorp/kubernetes v2.11.0 (signed by HashiCorp)

 

Terraform has created a lock file .terraform.lock.hcl to record the provider

selections it made above. Include this file in your version control repository

so that Terraform can guarantee to make the same selections by default when

you run "terraform init" in the future.

 

Terraform has been successfully initialized!

 

You may now begin working with Terraform. Try running "terraform plan" to see

any changes that are required for your infrastructure. All Terraform commands

should now work.

If you ever set or change modules or backend configuration for Terraform,

rerun this command to reinitialize your working directory. If you forget, other

commands will detect it and remind you to do so if necessary.

root@controlplane ~/terraform_challenge via 💠 default  


4. Create terraform resources frontend  for Kubernetes deployment & webapp-services for Kubernetes services

Created  TF files with all the parameters, Kindly clone repo or you can copy from GitLab 

git clone https://gitlab.com/nb-tech-support/devops.git

 Refer Below Video for more clarity )

root@controlplane ~/terraform_challenge via 💠 default kubectl get pods -A

NAMESPACE     NAME                                   READY   STATUS    RESTARTS      AGE

kube-system   coredns-64897985d-4nt2s                1/1     Running   0             12m

kube-system   coredns-64897985d-tj8hp                1/1     Running   0             12m

kube-system   etcd-controlplane                      1/1     Running   0             13m

kube-system   kube-apiserver-controlplane            1/1     Running   0             13m

kube-system   kube-controller-manager-controlplane   1/1     Running   0             13m

kube-system   kube-proxy-qvq69                       1/1     Running   0             12m

kube-system   kube-scheduler-controlplane            1/1     Running   0             13m

kube-system   weave-net-g54px                        2/2     Running   1 (12m ago)   12m

root@controlplane ~/terraform_challenge via 💠 default



Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge










Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user