Skip to content

Setting Up Instances, Kubernetes Cluster, Jenkins

AsimAzmi edited this page May 4, 2020 · 6 revisions

Using OpenStack Horizon For Creating 4 Instances:

Citing: https://iujetstream.atlassian.net/wiki/spaces/JWT/pages/44826638/Using+the+OpenStack+Horizon+GUI+Interface

Instance 1: DevengersJenkins(Jenkins Master) Instance 2: (Kubernetes-Master) Instance 3: (Kubernetes-Worker1) Instance 4: (Kubernetes-Worker2)

All the 4 instances are created using following steps:

  1. Set the Allocation : TG-CCR180043
  2. Click on the Project -> Compute -> Instances -> Launch Instance
  3. [Details]Select Instance Name -> As per your choice, Description -(Instance Functionality Description), Availability Zone-(Check Any), Count (Check -> 1) -> click on Next
  4. [Source] Select Boot Source -> Image -> Select 'JS-API-Featured-Ubuntu18-Feb-14-2020' '8.00 GB' Image. Click on next
  5. [Flavor] Select m1.quad for Kubernetes(master and slave node) Else Select m1.medium for Jenkins.
  6. [Networks] Select Devengers_net, Click on next
  7. [Network Ports] Skip Click on next
  8. [Security Groups] Select Devengers_security_group, click on next
  9. [Key Pair] Select key as Devengers, Click on Launch Instance
  10. Once the Instance is created -> On the extreme right side you will see Actions tab, Under that select dropdown from "Create Snapshot" -> Associate a Floating IP. Select a Floating IP that's available. Note the floating IP for every instance as you will need this to ssh the instance.

Installing Ansible on Ubuntu (Local Machine)

Citing:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-18-04#step-1-%E2%80%94-installing-ansible

  1. sudo apt-add-repository ppa:ansible/ansible
  2. sudo apt update
  3. sudo apt install ansible
  4. Then do, sudo vi /etc/ansible/hosts, paste the below content: [servers]
    <master_alias> ansible_host=<master_ip>
    <slave1_alias> ansible_host=<slave_ip>
    <slave2_alias>ansible_host=<slave_ip>
    [servers:vars]
    ansible_python_interpreter=/usr/bin/python3

Creating Kubernetes Cluster Using Kubeadm on Ubuntu (Local Machine)

Citing: https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-ubuntu-18-04

Once the ansible is installed using above step, then proceed with Kubernetes Cluster installation guidelines:

  1. Clone the github -> Go to the folder :- cd kube-cluster (Citing: https://iu.instructure.com/courses/1857048/discussion_topics/9220186).
  2. Open the file named hosts(nano hosts) and enter your Kubernetes Master and Slave IP's.
  3. Open the initial.yml nano (initial.yml) make sure the key name is right and key has permission 400.(if not use command "chmod 400 id_rsa"). You could get the key from the repo.
    -> Run the command ansible-playbook -i hosts ~/kube-cluster/initial.yml
  4. Don't change anything inside kube-dependencies.yml -> Run the ansible-playbook -i hosts kube-dependencies.yml
  5. Don't change anything inside master.yml -> Run the ansible-playbook -i hosts master.yml
  6. Don't change anything inside worker.yml -> Run the ansible-playbook -i hosts worker.yml
  7. Finally, Verify the cluster ssh ubuntu@Kubernetes_master_ip
  8. Get the status of the cluster -> kubectl get nodes

Setting Up Jenkins CI/CD Pipeline

  1. With your Jenkins Instance IP, ssh ubuntu@jenkins_instance_ip using your key.(id_rsa - you will find it in the repo.)

  2. Install Java 8 (Jenkins is built on java) using : sudo add-apt-repository ppa:webupd8team/java

    sudo apt-get update

    sudo apt install openjdk-8-jdk

  3. Install Jenkins on the instance: wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ >
/etc/apt/sources.list.d/jenkins.list'

sudo apt-get update

sudo apt-get install jenkins

  1. Check Status of the Jenkins using : systemctl status Jenkins
  2. If you face the error "sudo: no tty present and no askpass program specified" then follow the following steps: a.run " $ sudo visudo " -> this will open /etc/sudoers file. b.If your jenkins user is already in that file, then modify to look like this, add the below line, jenkins ALL=(ALL) NOPASSWD: ALL c.Save the file by doing Ctrl+O (dont save in tmp file. save in /etc/sudoers, confirm overwrite) d.Exit by doing Ctrl+X e. Relaunch your jenkins job you should not see the error message again :)
  3. Go to the URL (JenkinsInstanceIP:8080), you will get a link or a url copy the link and do cat "the link" -> this will display the initialadminpassword
  4. Copy the password and type on to browser, select -> installed selected plugins -> then set the profile remember the username and password.
  5. Change Port of the Jenkins, Jenkins By default works on 8080, but there is a chance that, your application is using the same port. (On a safe side change the port to 8090) Following are the steps: a. Go-to nano /etc/default/jenkins b. --httpPort=8090 or whatever port to JENKINS_ARGS. c. sudo service jenkins restart.
  6. Install Maven on JenkinsInstance sudo apt-get install maven
  7. Go to Manage Jenkins option -> Manage Plugins -> Available -> install the below mentioned plugins a. github integration. b. build pipeline. c. docker compose build step plugin. d. NodeJS plugin. e. build pipeline plugin. f. docker plugin. g. pipeline github.
  8. Goto Manage Jenkins option -> Global Tool Configuration -> Configure JDK, Maven and Git Path: a. Add JDK -> set Name: InstanceJDK , Set Java_HOME : /usr/lib/jvm/java-8-openjdk-amd64 b. Add GIT -> set Name: InstanceGIT , set Path to Git executable : git c. Add Maven -> set Name: InstanceMaven , set MAVEN_HOME : /usr/share/maven d. Add NodeJS -> set Name: InstanceNodeJS , Click on Install Automatically e. Add Docker -> set Name : InstanceDocker , Click on Install Automatically
  9. Go-to HomePage -> click on New-Item -> Enter an Item name -> select Pipeline -> Click on okay Enter Description -> Click on Poll SCM - Enter * * * * * (in schedule) Under the Option Pipeline, definition -> select Pipeline Script from SCM -> Select SCM as Git -> Select Repositories -> Repository URL put ->(https://github.com/airavata-courses/devengers.git) -> Select Branch -> */master Script Path : Jenkinsfile and click on Okay