Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
vagrant_kubernetes_install [2020/03/09 19:31] andonovjvagrant_kubernetes_install [2020/03/09 19:42] (current) andonovj
Line 63: Line 63:
 Please create the following files as follows: Please create the following files as follows:
  
-====Master Playbook File====+====Configure the Master Playbook==== 
 +Let's start building the master playbook: 
 <Code:none|Master Playbook File> <Code:none|Master Playbook File>
 --- ---
Line 109: Line 111:
       name: vagrant       name: vagrant
       group: docker       group: docker
 +    - name: Remove swapfile from /etc/fstab
 +    mount:
 +      name: "{{ item }}"
 +      fstype: swap
 +      state: absent
 +    with_items:
 +      - swap
 +      - none
 </Code> </Code>
 +
 +===Remove the swap===
 +Please bare in mind that the kubelet won't install if the swap is enabled, so we have to add the following:
 +
 +<Code:none|Remove the swap>
 +  - name: Disable swap
 +    command: swapoff -a
 +    when: ansible_swaptotal_mb > 0
 +</Code>
 +
 +===Install Kubelet, kubeadm, kubectl===
 +After that, we can add a task to install the: kubelet, kubeadm and kubectl using the below code.
 +
 +<Code:none|Add Kubelet, kubeadm and kubectl>
 +  - name: Add an apt signing key for Kubernetes
 +    apt_key:
 +      url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
 +      state: present
 +
 +  - name: Adding apt repository for Kubernetes
 +    apt_repository:
 +      repo: deb https://apt.kubernetes.io/ kubernetes-xenial main
 +      state: present
 +      filename: kubernetes.list
 +
 +  - name: Install Kubernetes binaries
 +    apt: 
 +      name: "{{ packages }}"
 +      state: present
 +      update_cache: yes
 +    vars:
 +      packages:
 +        - kubelet 
 +        - kubeadm 
 +        - kubectl
 +
 +  - name: Configure node ip
 +    lineinfile:
 +      path: /etc/default/kubelet
 +      line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}
 +
 +  - name: Restart kubelet
 +    service:
 +      name: kubelet
 +      daemon_reload: yes
 +      state: restarted
 +</Code>
 +
 +===Initialize the Kubernetes===
 +Finally, we can add the Tasks for the Initialization as follows:
 +
 +<Code:none|Initialize Kubernetes>
 +  - name: Initialize the Kubernetes cluster using kubeadm
 +    command: kubeadm init --apiserver-advertise-address="192.168.50.10" --apiserver-cert-extra-sans="192.168.50.10"  --node-name k8s-master --pod-network-cidr=192.168.0.0/16
 +</Code>
 +
 +===Configure Vagrant User for the Cluster===
 +Since we are using vagrant, we can setup vagrant to access the Kubernetes Cluster using the following Task:
 +
 +<Code:none|Configure Vagrant user>
 +  - name: Setup kubeconfig for vagrant user
 +    command: "{{ item }}"
 +    with_items:
 +     - mkdir -p /home/vagrant/.kube
 +     - cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
 +     - chown vagrant:vagrant /home/vagrant/.kube/config
 +</Code>
 +
 +===Configure the Network provider and policy engine===
 +<Code:none | Configure network provider and policy Engine>
 +  - name: Setup kubeconfig for vagrant user
 +    command: "{{ item }}"
 +    with_items:
 +     - mkdir -p /home/vagrant/.kube
 +     - cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
 +     - chown vagrant:vagrant /home/vagrant/.kube/config
 +</Code>
 +
 +====Configure the Node Playbook====
 +We will setup a join file which will be used in the playbook for the other nodes:
 +
 +<Code:none|Generate Join Command>
 +  - name: Generate join command
 +    command: kubeadm token create --print-join-command
 +    register: join_command
 +
 +  - name: Copy join command to local file
 +    local_action: copy content="{{ join_command.stdout_lines[0] }}" dest="./join-command"
 +</Code>
 +
 +The generated, from Kubernetes, join command will be saved in file called: "join-command" which will be executed by the playbook:
 +
 +===Configure handlers===
 +We have to also setup the handlers for checking the Docker daemon:
 +
 +<Code:none|Configure handlers>
 +  handlers:
 +    - name: docker status
 +      service: name=docker state=started
 +</Code>
 +
 +Finally we can configure the node-playbook.yml
 +
 +<Code:none|Node-playbook.yml config>
 +  - name: Copy the join command to server location
 +    copy: src=join-command dest=/tmp/join-command.sh mode=0777
 +
 +  - name: Join the node to cluster
 +    command: sh /tmp/join-command.sh
 +</Code>
 +
 +
  • vagrant_kubernetes_install.1583782266.txt.gz
  • Last modified: 2020/03/09 19:31
  • by andonovj