SlideShare a Scribd company logo
Kubespray
Deploy Kubernetes Cluster with Ansible
David Chang
Linkernetworks
BackEnd, DevOps,
Kubernetes
Headlines
• Deploy a K8s cluster on laptop
• Talk a little about Vagrant, a VM managing tool
• Kubespray & Ansible
• Try our localhost K8s cluster
Prerequisite
• virtualbox 5.1+ https://www.virtualbox.org/wiki/Downloads
• vagrant 2.0.x+ https://www.vagrantup.com/downloads.html
Install Ansible
# Ubuntu
apt-add-repository ppa:ansible/ansible 
&& apt-get update 
&& apt-get install -y python3 ansible
&& pip install netaddr
# Mac
pip install ansible
pip install netaddr
port install py27-netaddr # if you’re using MacPort
# netaddr is required by Kubespray
Let’s Get Started
clone https://github.com/kubernetes-incubator/kubespray.git
cd kubespray
vagrant up
# All done.
Let’s get to more details while waiting.
(It takes about 20 mins on my Mac lol)
Virtualbox
• K8s runs on servers, and Virtualbox is our server
virtualizer
• Virtualbox come with GUI, but we don’t use it because
• Clicking is time-consuming and engineers are lazy
• Bad for automation. Manual operation causes mistake.
• Lack of scalability. We can click 10 VMs but how about
100+ VMs.
Vagrant
• Kubespray provides vagrant for deploy K8s on VMs.
• Vagrant create you VMs with Vagrtantfile, a ruby based
script.
• A script is essential for automation.
• Vagrant bring VMs up & down within 1 command.
https://www.vagrantup.com/
Vagrant Operations
vagrant up (already done)
vagrant status
vagrant ssh k8s-01
vagrant destroy
What vagrant do?
• After vagrant up, vagrant create VMs with virtual box
• Vagrant also make necessary provisions to VMs
• Vagrant deploy k8s on to VMs with Kubespray
Vagrant & CICD
• Commit Vagrantfile to source code
• Bring VMs up & down
• Testing app on K8s and VMs
• Clean up VMs with vagrant
Ansible
• Ansible is a IT automation tools.
• Ansible-playbook is a script to modify remote servers
• Check components status on each step
• Come with lots of handy tools
(better than shell script)
Kubespray
• Deploy k8s with ansible-playbook
• Available on AWS, GCE, or baremetal
• High Available cluster
• Install K8s components to each servers
https://github.com/kubernetes-incubator/kubespray
Done!!
Test with Kubectl
Kubectl
• Kubectl is a k8s client tool to control k8s cluster
• Kubectl convert commands to API call to k8s cluster API
server
• Kubectl use authorized context
Deploy to Real Servers
• ansible-playbook
http://docs.ansible.com/ansible/latest/intro_installation.htm
l
• kubectl https://kubernetes.io/docs/tasks/tools/install-
kubectl/
• Check inventory/mycluster/hosts.ini
• playbook -i inventory/myCluster/hosts.ini cluster.yml
Thank you

More Related Content

Deploy High Availability Kubernetes with Kubespray

  • 3. Headlines • Deploy a K8s cluster on laptop • Talk a little about Vagrant, a VM managing tool • Kubespray & Ansible • Try our localhost K8s cluster
  • 4. Prerequisite • virtualbox 5.1+ https://www.virtualbox.org/wiki/Downloads • vagrant 2.0.x+ https://www.vagrantup.com/downloads.html
  • 5. Install Ansible # Ubuntu apt-add-repository ppa:ansible/ansible && apt-get update && apt-get install -y python3 ansible && pip install netaddr # Mac pip install ansible pip install netaddr port install py27-netaddr # if you’re using MacPort # netaddr is required by Kubespray
  • 6. Let’s Get Started clone https://github.com/kubernetes-incubator/kubespray.git cd kubespray vagrant up # All done. Let’s get to more details while waiting. (It takes about 20 mins on my Mac lol)
  • 7. Virtualbox • K8s runs on servers, and Virtualbox is our server virtualizer • Virtualbox come with GUI, but we don’t use it because • Clicking is time-consuming and engineers are lazy • Bad for automation. Manual operation causes mistake. • Lack of scalability. We can click 10 VMs but how about 100+ VMs.
  • 8. Vagrant • Kubespray provides vagrant for deploy K8s on VMs. • Vagrant create you VMs with Vagrtantfile, a ruby based script. • A script is essential for automation. • Vagrant bring VMs up & down within 1 command. https://www.vagrantup.com/
  • 9. Vagrant Operations vagrant up (already done) vagrant status vagrant ssh k8s-01 vagrant destroy
  • 10. What vagrant do? • After vagrant up, vagrant create VMs with virtual box • Vagrant also make necessary provisions to VMs • Vagrant deploy k8s on to VMs with Kubespray
  • 11. Vagrant & CICD • Commit Vagrantfile to source code • Bring VMs up & down • Testing app on K8s and VMs • Clean up VMs with vagrant
  • 12. Ansible • Ansible is a IT automation tools. • Ansible-playbook is a script to modify remote servers • Check components status on each step • Come with lots of handy tools (better than shell script)
  • 13. Kubespray • Deploy k8s with ansible-playbook • Available on AWS, GCE, or baremetal • High Available cluster • Install K8s components to each servers https://github.com/kubernetes-incubator/kubespray
  • 16. Kubectl • Kubectl is a k8s client tool to control k8s cluster • Kubectl convert commands to API call to k8s cluster API server • Kubectl use authorized context
  • 17. Deploy to Real Servers • ansible-playbook http://docs.ansible.com/ansible/latest/intro_installation.htm l • kubectl https://kubernetes.io/docs/tasks/tools/install- kubectl/ • Check inventory/mycluster/hosts.ini • playbook -i inventory/myCluster/hosts.ini cluster.yml