-
Notifications
You must be signed in to change notification settings - Fork 0
Setting Up Instances, Kubernetes Cluster, Jenkins
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:
- Set the Allocation : TG-CCR180043
- Click on the Project -> Compute -> Instances -> Launch Instance
- [Details]Select Instance Name -> As per your choice, Description -(Instance Functionality Description), Availability Zone-(Check Any), Count (Check -> 1) -> click on Next
- [Source] Select Boot Source -> Image -> Select 'JS-API-Featured-Ubuntu18-Feb-14-2020' '8.00 GB' Image. Click on next
- [Flavor] Select m1.quad for Kubernetes(master and slave node) Else Select m1.medium for Jenkins.
- [Networks] Select Devengers_net, Click on next
- [Network Ports] Skip Click on next
- [Security Groups] Select Devengers_security_group, click on next
- [Key Pair] Select key as Devengers, Click on Launch Instance
- 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.
- sudo apt-add-repository ppa:ansible/ansible
- sudo apt update
- sudo apt install ansible
- 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
Once the ansible is installed using above step, then proceed with Kubernetes Cluster installation guidelines:
- Clone the github -> Go to the folder :- cd kube-cluster (Citing: https://iu.instructure.com/courses/1857048/discussion_topics/9220186).
- Open the file named hosts(nano hosts) and enter your Kubernetes Master and Slave IP's.
- 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 - Don't change anything inside kube-dependencies.yml -> Run the ansible-playbook -i hosts kube-dependencies.yml
- Don't change anything inside master.yml -> Run the ansible-playbook -i hosts master.yml
- Don't change anything inside worker.yml -> Run the ansible-playbook -i hosts worker.yml
- Finally, Verify the cluster ssh ubuntu@Kubernetes_master_ip
- Get the status of the cluster -> kubectl get nodes
-
With your Jenkins Instance IP, ssh ubuntu@jenkins_instance_ip using your key.(id_rsa - you will find it in the repo.)
-
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
-
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
- Check Status of the Jenkins using : systemctl status Jenkins
- 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 :)
- 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
- Copy the password and type on to browser, select -> installed selected plugins -> then set the profile remember the username and password.
- 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.
- Install Maven on JenkinsInstance sudo apt-get install maven
- 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.
- 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
- 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