Skip to content

Launching & Configuring Instances

Hrishikesh Paul edited this page Mar 29, 2021 · 6 revisions

Inspired from this blog.

Dependencies

Steps to create VMs

  • In the folder root of the jetstream_kubespray repository,
$ source XX-XXXXXXXX-openrc.sh # make sure openstack cli works
$ git clone https://github.com/airavata-courses/scrapbook
$ git checkout k8-cluster-setup

$ openstack floating ip create public
$ openstack floating ip list # keep track of the floating ip just created

$ cd inventory/kubejetstream

Edit the following in the cluster.tfvars file.

  1. cluster_name (line 2)
  2. k8s_master_fips (line 28. Put the floating IP that you just created)
  3. network_name (line 61)

These need to be changed because using the same configs without changing them will cause the VMs to not be created as they already exist.

$ bash terraform_init.sh
$ bash terraform_apply.sh

# after the installation has been complete, the output will have the IP of the master node.
$ ssh ubuntu@<IP>

To delete the current configurations run,

bash terraform_destroy.sh

Steps to set up Kubeternetes

  • Change folder back to the root of the jetstream_kubespray repository,
# this is to ping the servers and make sure they are running

$ pip install -r requirements.txt
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa
$ ansible -i inventory/kubejetstream/hosts -m ping all

  • Edit the file: inventory/kubejetstream/group_vars/k8-cluster/k8-cluster.yml at line 255 and include the floating IP of your master node.

Lastly, run

$ bash k8s_install.sh

Once this completes (in about 10 minutes), to see if everything was installed correctly you can run,

$ ssh ubuntu@<ip_of_master_node>
$ sudo su
$ kubectl get pods --all-namespaces # this should give you a list of all the pods running in the control plane

Steps to configure Jenkins and K8 Cluster

For CD to work, Jenkins and the K8 cluster need to be connected. Since we are using SSH to connect them, we need to establish a key/value pair connection.

  1. Generate a key-value pair

    $ ssh-keygen -t rsa -b 4096
    $ cd ~/.ssh
    $ cat id_rsa.pub
    

Copy the contents of the id_rsa.pub file. This is the public key that needs to be added to the kubernetes cluster.

  1. Add the public key to the kubernetes cluster (master node)

    $ ssh ubuntu@<ip_of_master>
    $ cd ~/.ssh
    $ vi authorized_keys
    $ <paste the value that you copied before>
    
  2. Lastly, root access needs to be given to the default user (ubuntu). This is because form Jenkins we cannot run a sudo su command to change the user.

    # adding the kube config to the ubunut user
    $ ssh ubuntu@<ip_of_master>
    
    # give kubectl access to ubuntu user
    $ mkdir -p /home/$USER/.kube
    $ cp -i /etc/kubernetes/admin.conf /home/$USER/.kube/config
    $ chown $USER:$USER /home/$USER/.kube/config
    

    Add the ubuntu users in the sudoers file

    $ vi /etc/sudoers
    
    
    # under root write the same for the ubuntu user
    # your sudoers file should look like this
    
    # User privilege specification
    root	ALL=(ALL:ALL) ALL
    ubuntu  ALL=(ALL:ALL) ALL
    

To see if its working, in the ubuntu user, run kubectl get nodes

If you get an error which says could not connect to localhost try to redo the steps by verifying the user privileges.

Clone this wiki locally