SlideShare a Scribd company logo
1 of 81
Download to read offline
Hong Kong Open Source
Conference 2020
Ansible: From VM to Kubernetes
Edison Wong
2020-06-13
Wong Hoi Sing, Edison
●
2005 - Drupal Developer & Contributor
– https://drupal.org/user/33940
●
2008 - HKDUG Co-founder
– https://groups.drupal.org/drupalhk
●
2010 - CEO, PantaRei Design
– hswong3i@pantarei-design.com
PantaRei Design
●
Everything Changes and Nothing Remains Still
●
Reinvent Enterprise with Open Source Software and Cloud Computing
●
Hong Kong based FOSS service provider
– Content Management System (CMS) with Drupal
– Cloud Hosting Solution with Amazon Web Services (AWS)
– Team collaborate solution with Atlassian
●
Business Partner with industry leaders
– 2012, AWS Consulting Partner
– 2013, Acquia Partner
– 2013, Atlassian Experts
– 2014, Rackspace Hosting Partner
●
http://pantarei-design.com
Outline
●
HKOSCON 2019
●
Why DevOps with Ansible?
●
Ansible with VM
●
Ansible with Docker
●
Ansible with Kubernetes
●
Tips & Tricks
●
Roadmap
●
Q&A
HKOSCON 2019
●
Ansible Role with Molecule + LXD
●
Docker Build with Ansible
●
Kubernetes with Molecule +
Vagrant + VirtualBox
Ansible Role with Molecule +
LXD
●
Molecule LXD driver + Travis CI
●
Could mock up 80% use cases
●
Lack of cgroup/network/device support
●
(2020) Improved with Vagrant + Libvirt
+ Travis CI
Docker Build with Ansible
●
Ansible playbook drive by
Dockerfile, inside target container
●
Reduce custom bash shell scripting
●
(2020) Improved with Molecule
Docker driver + `docker commit`
Kubernetes with Molecule +
Vagrant + VirtualBox
●
Molecule Vagrant driver +
VirtualBox for local test
●
Slow, limited OS, no Travis CI
●
(2020) Improved with Vagrant +
Libvirt + Travis CI
Why DevOps with Ansible?
●
SysAdmin Daily Difficulties
●
Why DevOps?
●
Why Ansible?
SysAdmin Daily Difficulties
●
Different deployment target
●
Test logic before deploy
●
Complex cluster management
●
Documentation
●
No time for learning
SysAdmin Daily Difficulties
(cont.)
●
Write-once for all cases
– Native/Bare Metal/VM
– Docker/LXD/Vagrant
– OpenStack/AWS/GCE/Azure
– Kubernetes/OpenShift/AKS/GKE/EKS
Why DevOps?
●
Manual install
– Non-repeatable
●
Manual install with document
– Difficult to manage (Docs to Action)
– Always async with production
●
Manual scripting
– Difficult for everything: learn, write, error detection,
debug, etc…
Why DevOps? (cont.)
●
DevOps
– Deployment logic as code (i.e. revision
with GIT)
– With error detection and debug tools
– Manage multiple deployment target at
once (e.g. data center, clustering)
Why Ansible?
●
Writing “tasks” in YAML
– Human readable == minimize
documentation
– Easy to learn, when compare with
Ruby for Chef or Puppet
Why Ansible? (cont.)
A lot of reusable modules
– Simplify complicated logic with error
detection
– Or running “shell” command directly
Why Ansible? (cont.)
●
Simple requirement
– Python and Password-less SSH
– Agent-less for managed node
Ansible with VM
●
Ansible CLI
●
Ansible Playbook
●
Ansible Role
●
Molecule + Delegate
●
Demo: ansible-role-sshd
Ansible CLI
●
Running command on remote guest is
simple
– ansible -i guest1,guest2, -m ping
– ansible -i guest1,guest2, -m apt -a ‘name=vim
state=present’
– ansible -i guest1,guest2, -m shell -a ‘uname -a’
Ansible Playbook
●
Running multiple “task” once together
●
Finer control than running with CLI
●
Define your inventory then play with it
– ansible-playbook -i inventory/all/hosts
playbooks/setup-everything.yml
Ansible Role
●
Not just “Tasks”, but also:
– Default over-writable variables
– Internal static variables
– Static files for copy
– Template files
– Event handlers
●
A basic build block for complex architecture
– Use Playbook to include different Roles
Ansible Role (cont.)
●
Create a new role with ansible-galaxy
– mkdir ~/.ansible/roles
– cd ~/.ansible/roles
– ansible-galaxy init dummy
●
You could now test it (run via your localhost)
– cd ~/.ansible/roles/dummy
– ansible-playbook -i tests/inventory tests/test.yml
●
Limited functionality
Ansible Role (cont.)
●
Molecule
– Testing framework for Ansible
– Written in Ansible and Python style
– Write your test case in standard Ansible style
– Manage test environment life-cycle for you
– Code lint
– Idempotence (i.e. run twice to confirm no extra
changes)
Ansible Role (cont.)
●
Create a new Role with molecule
– cd ~/.ansible/roles
– molecule init role -r dummy2 -d docker
– molecule init role -r dummy3 -d lxd
– molecule init role -r dummy4 -d vagrant
●
Now you could run test inside Docker
– cd ~/.ansible/roles/dummy2
– molecule test
Molecule + Delegate (cont.)
●
Molecule + Delegate
= Ansible Role Installer
– Roles dependency management
– No custom wrapper playbook
– Install into localhost
Demo: ansible-role-sshd
●
https://github.com/alvistack/ansible-role
-sshd
– mkdir ~/.ansible/roles && cd ~/.ansible/roles
– git clone
https://github.com/alvistack/ansible-role-
sshd.git sshd && cd sshd
– molecule converge
Ansible with Docker
●
Why NOT Dockerfile?
●
Why NOT ansible-bender?
●
Molecule + Docker
●
Demo: docker-jira
Why NOT Dockerfile?
●
Back to the origin: why still
custom shell scripting?
– Difficult for everything: learn, write,
error detection, debug, etc…
Why NOT ansible-bender?
●
https://github.com/ansible-commu
nity/ansible-bender
– Build Docker Image with standard
Ansible Playbook
– Podman + Buildah based
– Just need basic Python support inside
target container
Why NOT ansible-bender?
(cont.)
●
PROS
– Push image to DockerHub once build
successful
●
CONS
– Could NOT integrate with Travis CI
– Only support Podman + Buildah
– Not compatible with Molecule
Molecule + Docker
●
Molecule + Docker
= Docker image creator
●
Support both Docker and Podman
●
Run as standard Molecule test case
●
`docker commit` during destroy phase
●
Push result Docker image to remote registry
Molecule + Docker (cont.)
●
molecule/*/Dockerfile.j2
– Just define meta data (e.g. FROM,
EXPOSE, ENTRYPOINT, CMD, etc)
– Minimal RUN (e.g. groupadd,
useradd, etc)
Molecule + Docker (cont.)
●
molecule/*/create.yml
– Create initial base image with meta
data as Dockerfile.j2
– Override CMD with `base -c “sleep
infinity”` on-the-fly for running test
Molecule + Docker (cont.)
●
molecule/*/destroy.yml
– Fetch base image meta data
– Commit running Docker instance
with base image’s CMD/ENTRYPOINT
Demo: docker-jira
●
https://github.com/alvistack/docker-jira
– Docker Image packaging for Atlassian JIRA
– Molecule + Docker
– All used Roles are Vagrant + Libvirt tested
– Push to DockerHub once Travis CI passed
Ansible with Kubernetes
●
Molecule + Vagrant + Libvirt
●
Demo: ansible-collection-
kubernetes
Molecule + Vagrant + Libvirt
●
In case of Ceph OSD, truth block device is
required
– Not support file-based loop device
●
In case of Weave, each Kubernetes node
must have unique machine ID
– With LXD all instance get the same host
machine ID
Molecule + Vagrant + Libvirt
(cont.)
●
Molecule + Vagrant + Libvirt
= 100% mock up
●
Support Travis CI
●
Support multiple instances for cluster test
●
Support multiple OS
●
Fully support cgroup/network/block/etc
Demo: ansible-collection-
kubernetes
●
Ansible + Ceph + Kubernetes + Addon
– All Roles tested with Vagrant + Libvirt individually
– Simply clone-and-play
●
Multiple OS Support
– Ubuntu 18.04/19.10/20.04
– RHEL/CentOS 7/8
– openSUSE Leap 15.1
– Debian 10
– Fedora 32
●
https://github.com/alvistack/ansible-collection-kubernetes
Demo: ansible-collection-
kubernetes (cont.)
●
Support different deployment style
– Single All-in-One
– (Kubernetes + Ceph) x3
– Kubernetes x3 + Ceph x3
– Kubernetes xN + Ceph xN
Demo: ansible-collection-
kubernetes (cont.)
●
Kubernetes 1.18.3
– CRI-O
– CNI: Weave
– CSI: CephFS
– Ingress Nginx
●
Ceph 15.2.3
Demo: ansible-collection-
kubernetes (cont.)
●
Support individual application
deployment per namespace, e.g.
– Drupal + Apache + PHP-FPM + MariaDB
– Jira + Apache + PostgreSQL
●
Support HTTPS with Let’s Encrypt
Demo: ansible-collection-
kubernetes (cont.)
●
Fetch source
– git clone https://github.com/alvistack/
ansible-collection-kubernetes.git && cd
ansible-collection-kubernetes
– git submodule update --init –recursive
alvistack/ansible-collection-
kubernetes (cont.)
●
Setup inventory
– cp -rfp inventory/default inventory/all
– vi inventory/all/hosts
alvistack/ansible-collection-
kubernetes (cont.)
●
Run the playbook
– ansible-playbook -i inventory/all/hosts
playbooks/coverge.yml
Tips & Tricks
●
Always Start with Test Cases
●
Simple Deployment Goes Molecule + Delegate
●
Test Cases Always Goes Molecule + Vagrant +
Libvirt + Travis CI
●
Create Docker Image After Molecule Test Case
by Commit
Roadmap
●
Migrate everything from Docker
to Podman/Buildah/Skopeo
●
Handle Kubernetes Addons with
Ansible Operator
Q&A
Contact Us
●
Address: Unit 326, 3/F, Building 16W, No.16
Science Park West Avenue, Hong Kong Science
Park, Shatin, N.T.
●
Phone: +852 3576 3812
●
Fax: +852 3753 3663
●
Email: sales@pantarei-design.com
●
Web: http://pantarei-design.com

More Related Content

What's hot

What's hot (20)

[Szjug] Docker. Does it matter for java developer?
[Szjug] Docker. Does it matter for java developer?[Szjug] Docker. Does it matter for java developer?
[Szjug] Docker. Does it matter for java developer?
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Server
 
Docker Workshop Birthday #3
Docker Workshop Birthday #3Docker Workshop Birthday #3
Docker Workshop Birthday #3
 
Virtualization with Vagrant (ua.pycon 2011)
Virtualization with Vagrant (ua.pycon 2011)Virtualization with Vagrant (ua.pycon 2011)
Virtualization with Vagrant (ua.pycon 2011)
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
 
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
 
Zend Expressive in 15 Minutes
Zend Expressive in 15 MinutesZend Expressive in 15 Minutes
Zend Expressive in 15 Minutes
 
Vagrant + Docker
Vagrant + DockerVagrant + Docker
Vagrant + Docker
 
Dockercon EU 2014
Dockercon EU 2014Dockercon EU 2014
Dockercon EU 2014
 
Vagrant For DevOps
Vagrant For DevOpsVagrant For DevOps
Vagrant For DevOps
 
Vagrant-Overview
Vagrant-OverviewVagrant-Overview
Vagrant-Overview
 
Arquitecturas de microservicios - Codemotion 2014
Arquitecturas de microservicios  -  Codemotion 2014Arquitecturas de microservicios  -  Codemotion 2014
Arquitecturas de microservicios - Codemotion 2014
 
Super combinators
Super combinatorsSuper combinators
Super combinators
 
About docker in GDG Seoul
About docker in GDG SeoulAbout docker in GDG Seoul
About docker in GDG Seoul
 
Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)
Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)
Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)
 
Gitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a proGitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a pro
 
Infrastructure as Data with Ansible
Infrastructure as Data with AnsibleInfrastructure as Data with Ansible
Infrastructure as Data with Ansible
 
Docker Compose to Production with Docker Swarm
Docker Compose to Production with Docker SwarmDocker Compose to Production with Docker Swarm
Docker Compose to Production with Docker Swarm
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 

Similar to [HKOSCON][20200613][ Ansible: From VM to Kubernetes]

LXC Docker and the Future of Software Delivery
LXC Docker and the Future of Software DeliveryLXC Docker and the Future of Software Delivery
LXC Docker and the Future of Software Delivery
Docker, Inc.
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Docker, Inc.
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
Docker, Inc.
 

Similar to [HKOSCON][20200613][ Ansible: From VM to Kubernetes] (20)

[HKOSCON][20220611][AlviStack: Hong Kong Based Kubernetes Distribution]
[HKOSCON][20220611][AlviStack: Hong Kong Based Kubernetes Distribution][HKOSCON][20220611][AlviStack: Hong Kong Based Kubernetes Distribution]
[HKOSCON][20220611][AlviStack: Hong Kong Based Kubernetes Distribution]
 
[BarCamp2018][20180915][Tips for Virtual Hosting on Kubernetes]
[BarCamp2018][20180915][Tips for Virtual Hosting on Kubernetes][BarCamp2018][20180915][Tips for Virtual Hosting on Kubernetes]
[BarCamp2018][20180915][Tips for Virtual Hosting on Kubernetes]
 
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
[HKOSCON][20180616][Containerized High Availability Virtual Hosting Deploymen...
 
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3 Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
Puppet Camp Seattle 2014: Docker and Puppet: 1+1=3
 
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
 
Introduction to Docker at the Azure Meet-up in New York
Introduction to Docker at the Azure Meet-up in New YorkIntroduction to Docker at the Azure Meet-up in New York
Introduction to Docker at the Azure Meet-up in New York
 
Kubernetes: training micro-dragons for a serious battle
Kubernetes: training micro-dragons for a serious battleKubernetes: training micro-dragons for a serious battle
Kubernetes: training micro-dragons for a serious battle
 
DevEx | there’s no place like k3s
DevEx | there’s no place like k3sDevEx | there’s no place like k3s
DevEx | there’s no place like k3s
 
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme PetazzoniWorkshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
 
Introduction to Docker, December 2014 "Tour de France" Edition
Introduction to Docker, December 2014 "Tour de France" EditionIntroduction to Docker, December 2014 "Tour de France" Edition
Introduction to Docker, December 2014 "Tour de France" Edition
 
Introduction to Docker at Glidewell Laboratories in Orange County
Introduction to Docker at Glidewell Laboratories in Orange CountyIntroduction to Docker at Glidewell Laboratories in Orange County
Introduction to Docker at Glidewell Laboratories in Orange County
 
LXC, Docker, and the future of software delivery | LinuxCon 2013
LXC, Docker, and the future of software delivery | LinuxCon 2013LXC, Docker, and the future of software delivery | LinuxCon 2013
LXC, Docker, and the future of software delivery | LinuxCon 2013
 
LXC Docker and the Future of Software Delivery
LXC Docker and the Future of Software DeliveryLXC Docker and the Future of Software Delivery
LXC Docker and the Future of Software Delivery
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShift
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
 
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
 
Deploy Multinode GitLab Runner in openSUSE 15.1 Instances with Ansible Automa...
Deploy Multinode GitLab Runner in openSUSE 15.1 Instances with Ansible Automa...Deploy Multinode GitLab Runner in openSUSE 15.1 Instances with Ansible Automa...
Deploy Multinode GitLab Runner in openSUSE 15.1 Instances with Ansible Automa...
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 

More from Wong Hoi Sing Edison

More from Wong Hoi Sing Edison (20)

[HKDUG] #20180512 - Fix Hacked Drupal with GIT
[HKDUG] #20180512 - Fix Hacked Drupal with GIT[HKDUG] #20180512 - Fix Hacked Drupal with GIT
[HKDUG] #20180512 - Fix Hacked Drupal with GIT
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
 
[20160314][CUHK][CSCI4140]Life of an Agile Team]
[20160314][CUHK][CSCI4140]Life of an Agile Team][20160314][CUHK][CSCI4140]Life of an Agile Team]
[20160314][CUHK][CSCI4140]Life of an Agile Team]
 
BarCamp Hong Kong 2015 - AuthBucket - Open Source Identity Management System
BarCamp Hong Kong 2015 - AuthBucket - Open Source Identity Management SystemBarCamp Hong Kong 2015 - AuthBucket - Open Source Identity Management System
BarCamp Hong Kong 2015 - AuthBucket - Open Source Identity Management System
 
[HKDUG] #20151017 - BarCamp 2015 - Drupal 8 is Coming! Are You Ready?
[HKDUG] #20151017 - BarCamp 2015 - Drupal 8 is Coming! Are You Ready?[HKDUG] #20151017 - BarCamp 2015 - Drupal 8 is Coming! Are You Ready?
[HKDUG] #20151017 - BarCamp 2015 - Drupal 8 is Coming! Are You Ready?
 
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
[HKDUG] #20160626 - HKOSCon 2015 - Website DIY with Drupal 8
 
DruStack- a mobile-friendly web content management system (cms
DruStack- a mobile-friendly web content management system (cmsDruStack- a mobile-friendly web content management system (cms
DruStack- a mobile-friendly web content management system (cms
 
drustack a mobile-friendly web content management system (cms)
drustack   a mobile-friendly web content management system (cms)drustack   a mobile-friendly web content management system (cms)
drustack a mobile-friendly web content management system (cms)
 
CUHK CSCI 4140 2015 Spring Guest Lecture - Agile Development
CUHK CSCI 4140 2015 Spring Guest Lecture - Agile DevelopmentCUHK CSCI 4140 2015 Spring Guest Lecture - Agile Development
CUHK CSCI 4140 2015 Spring Guest Lecture - Agile Development
 
Open Innovation Lab (OIL) - 20150227 - GIT Intro Workshop
Open Innovation Lab (OIL) - 20150227 - GIT Intro WorkshopOpen Innovation Lab (OIL) - 20150227 - GIT Intro Workshop
Open Innovation Lab (OIL) - 20150227 - GIT Intro Workshop
 
IT Entrepreneurship Talk - City University of Hong Kong
IT Entrepreneurship Talk - City University of Hong KongIT Entrepreneurship Talk - City University of Hong Kong
IT Entrepreneurship Talk - City University of Hong Kong
 
OSS Community Meeting - OSS Community Management for Dummy
OSS Community Meeting - OSS Community Management for DummyOSS Community Meeting - OSS Community Management for Dummy
OSS Community Meeting - OSS Community Management for Dummy
 
Barcamp Hong Kong 2014 - Introduction to GIT
Barcamp Hong Kong 2014 - Introduction to GITBarcamp Hong Kong 2014 - Introduction to GIT
Barcamp Hong Kong 2014 - Introduction to GIT
 
Barcamp Hong Kong 2014 - Commercial Use of OSS Web Content Management System
Barcamp Hong Kong 2014 - Commercial Use of OSS Web Content Management SystemBarcamp Hong Kong 2014 - Commercial Use of OSS Web Content Management System
Barcamp Hong Kong 2014 - Commercial Use of OSS Web Content Management System
 
Hong Kong Drupal User Group - Nov 8th
Hong Kong Drupal User Group - Nov 8thHong Kong Drupal User Group - Nov 8th
Hong Kong Drupal User Group - Nov 8th
 
Entrepreneurship Talk
Entrepreneurship TalkEntrepreneurship Talk
Entrepreneurship Talk
 
Open Source.HK Workshop - 2014 Oct 11th
Open Source.HK Workshop - 2014 Oct 11thOpen Source.HK Workshop - 2014 Oct 11th
Open Source.HK Workshop - 2014 Oct 11th
 
Barcamp Macau 2014 - Introduction to GIT
Barcamp Macau 2014 - Introduction to GITBarcamp Macau 2014 - Introduction to GIT
Barcamp Macau 2014 - Introduction to GIT
 
Barcamp Macau 2014 - Introduction to AWS
Barcamp Macau 2014 - Introduction to AWSBarcamp Macau 2014 - Introduction to AWS
Barcamp Macau 2014 - Introduction to AWS
 
Open Innovation Lab (OIL) - 2014 Sep 26th
Open Innovation Lab (OIL) - 2014 Sep 26thOpen Innovation Lab (OIL) - 2014 Sep 26th
Open Innovation Lab (OIL) - 2014 Sep 26th
 

Recently uploaded

Recently uploaded (20)

[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 

[HKOSCON][20200613][ Ansible: From VM to Kubernetes]

  • 1. Hong Kong Open Source Conference 2020 Ansible: From VM to Kubernetes Edison Wong 2020-06-13
  • 2. Wong Hoi Sing, Edison ● 2005 - Drupal Developer & Contributor – https://drupal.org/user/33940 ● 2008 - HKDUG Co-founder – https://groups.drupal.org/drupalhk ● 2010 - CEO, PantaRei Design – hswong3i@pantarei-design.com
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. PantaRei Design ● Everything Changes and Nothing Remains Still ● Reinvent Enterprise with Open Source Software and Cloud Computing ● Hong Kong based FOSS service provider – Content Management System (CMS) with Drupal – Cloud Hosting Solution with Amazon Web Services (AWS) – Team collaborate solution with Atlassian ● Business Partner with industry leaders – 2012, AWS Consulting Partner – 2013, Acquia Partner – 2013, Atlassian Experts – 2014, Rackspace Hosting Partner ● http://pantarei-design.com
  • 8.
  • 9. Outline ● HKOSCON 2019 ● Why DevOps with Ansible? ● Ansible with VM ● Ansible with Docker ● Ansible with Kubernetes ● Tips & Tricks ● Roadmap ● Q&A
  • 10. HKOSCON 2019 ● Ansible Role with Molecule + LXD ● Docker Build with Ansible ● Kubernetes with Molecule + Vagrant + VirtualBox
  • 11. Ansible Role with Molecule + LXD ● Molecule LXD driver + Travis CI ● Could mock up 80% use cases ● Lack of cgroup/network/device support ● (2020) Improved with Vagrant + Libvirt + Travis CI
  • 12. Docker Build with Ansible ● Ansible playbook drive by Dockerfile, inside target container ● Reduce custom bash shell scripting ● (2020) Improved with Molecule Docker driver + `docker commit`
  • 13. Kubernetes with Molecule + Vagrant + VirtualBox ● Molecule Vagrant driver + VirtualBox for local test ● Slow, limited OS, no Travis CI ● (2020) Improved with Vagrant + Libvirt + Travis CI
  • 14. Why DevOps with Ansible? ● SysAdmin Daily Difficulties ● Why DevOps? ● Why Ansible?
  • 15. SysAdmin Daily Difficulties ● Different deployment target ● Test logic before deploy ● Complex cluster management ● Documentation ● No time for learning
  • 16. SysAdmin Daily Difficulties (cont.) ● Write-once for all cases – Native/Bare Metal/VM – Docker/LXD/Vagrant – OpenStack/AWS/GCE/Azure – Kubernetes/OpenShift/AKS/GKE/EKS
  • 17.
  • 18. Why DevOps? ● Manual install – Non-repeatable ● Manual install with document – Difficult to manage (Docs to Action) – Always async with production ● Manual scripting – Difficult for everything: learn, write, error detection, debug, etc…
  • 19. Why DevOps? (cont.) ● DevOps – Deployment logic as code (i.e. revision with GIT) – With error detection and debug tools – Manage multiple deployment target at once (e.g. data center, clustering)
  • 20. Why Ansible? ● Writing “tasks” in YAML – Human readable == minimize documentation – Easy to learn, when compare with Ruby for Chef or Puppet
  • 21. Why Ansible? (cont.) A lot of reusable modules – Simplify complicated logic with error detection – Or running “shell” command directly
  • 22. Why Ansible? (cont.) ● Simple requirement – Python and Password-less SSH – Agent-less for managed node
  • 23.
  • 24.
  • 25. Ansible with VM ● Ansible CLI ● Ansible Playbook ● Ansible Role ● Molecule + Delegate ● Demo: ansible-role-sshd
  • 26. Ansible CLI ● Running command on remote guest is simple – ansible -i guest1,guest2, -m ping – ansible -i guest1,guest2, -m apt -a ‘name=vim state=present’ – ansible -i guest1,guest2, -m shell -a ‘uname -a’
  • 27. Ansible Playbook ● Running multiple “task” once together ● Finer control than running with CLI ● Define your inventory then play with it – ansible-playbook -i inventory/all/hosts playbooks/setup-everything.yml
  • 28.
  • 29.
  • 30. Ansible Role ● Not just “Tasks”, but also: – Default over-writable variables – Internal static variables – Static files for copy – Template files – Event handlers ● A basic build block for complex architecture – Use Playbook to include different Roles
  • 31. Ansible Role (cont.) ● Create a new role with ansible-galaxy – mkdir ~/.ansible/roles – cd ~/.ansible/roles – ansible-galaxy init dummy ● You could now test it (run via your localhost) – cd ~/.ansible/roles/dummy – ansible-playbook -i tests/inventory tests/test.yml ● Limited functionality
  • 32.
  • 33. Ansible Role (cont.) ● Molecule – Testing framework for Ansible – Written in Ansible and Python style – Write your test case in standard Ansible style – Manage test environment life-cycle for you – Code lint – Idempotence (i.e. run twice to confirm no extra changes)
  • 34.
  • 35. Ansible Role (cont.) ● Create a new Role with molecule – cd ~/.ansible/roles – molecule init role -r dummy2 -d docker – molecule init role -r dummy3 -d lxd – molecule init role -r dummy4 -d vagrant ● Now you could run test inside Docker – cd ~/.ansible/roles/dummy2 – molecule test
  • 36.
  • 37. Molecule + Delegate (cont.) ● Molecule + Delegate = Ansible Role Installer – Roles dependency management – No custom wrapper playbook – Install into localhost
  • 38. Demo: ansible-role-sshd ● https://github.com/alvistack/ansible-role -sshd – mkdir ~/.ansible/roles && cd ~/.ansible/roles – git clone https://github.com/alvistack/ansible-role- sshd.git sshd && cd sshd – molecule converge
  • 39.
  • 40.
  • 41.
  • 42.
  • 43. Ansible with Docker ● Why NOT Dockerfile? ● Why NOT ansible-bender? ● Molecule + Docker ● Demo: docker-jira
  • 44. Why NOT Dockerfile? ● Back to the origin: why still custom shell scripting? – Difficult for everything: learn, write, error detection, debug, etc…
  • 45. Why NOT ansible-bender? ● https://github.com/ansible-commu nity/ansible-bender – Build Docker Image with standard Ansible Playbook – Podman + Buildah based – Just need basic Python support inside target container
  • 46. Why NOT ansible-bender? (cont.) ● PROS – Push image to DockerHub once build successful ● CONS – Could NOT integrate with Travis CI – Only support Podman + Buildah – Not compatible with Molecule
  • 47.
  • 48. Molecule + Docker ● Molecule + Docker = Docker image creator ● Support both Docker and Podman ● Run as standard Molecule test case ● `docker commit` during destroy phase ● Push result Docker image to remote registry
  • 49. Molecule + Docker (cont.) ● molecule/*/Dockerfile.j2 – Just define meta data (e.g. FROM, EXPOSE, ENTRYPOINT, CMD, etc) – Minimal RUN (e.g. groupadd, useradd, etc)
  • 50.
  • 51. Molecule + Docker (cont.) ● molecule/*/create.yml – Create initial base image with meta data as Dockerfile.j2 – Override CMD with `base -c “sleep infinity”` on-the-fly for running test
  • 52.
  • 53. Molecule + Docker (cont.) ● molecule/*/destroy.yml – Fetch base image meta data – Commit running Docker instance with base image’s CMD/ENTRYPOINT
  • 54.
  • 55. Demo: docker-jira ● https://github.com/alvistack/docker-jira – Docker Image packaging for Atlassian JIRA – Molecule + Docker – All used Roles are Vagrant + Libvirt tested – Push to DockerHub once Travis CI passed
  • 56.
  • 57.
  • 58.
  • 59. Ansible with Kubernetes ● Molecule + Vagrant + Libvirt ● Demo: ansible-collection- kubernetes
  • 60. Molecule + Vagrant + Libvirt ● In case of Ceph OSD, truth block device is required – Not support file-based loop device ● In case of Weave, each Kubernetes node must have unique machine ID – With LXD all instance get the same host machine ID
  • 61. Molecule + Vagrant + Libvirt (cont.) ● Molecule + Vagrant + Libvirt = 100% mock up ● Support Travis CI ● Support multiple instances for cluster test ● Support multiple OS ● Fully support cgroup/network/block/etc
  • 62.
  • 63.
  • 64. Demo: ansible-collection- kubernetes ● Ansible + Ceph + Kubernetes + Addon – All Roles tested with Vagrant + Libvirt individually – Simply clone-and-play ● Multiple OS Support – Ubuntu 18.04/19.10/20.04 – RHEL/CentOS 7/8 – openSUSE Leap 15.1 – Debian 10 – Fedora 32 ● https://github.com/alvistack/ansible-collection-kubernetes
  • 65.
  • 66. Demo: ansible-collection- kubernetes (cont.) ● Support different deployment style – Single All-in-One – (Kubernetes + Ceph) x3 – Kubernetes x3 + Ceph x3 – Kubernetes xN + Ceph xN
  • 67.
  • 68. Demo: ansible-collection- kubernetes (cont.) ● Kubernetes 1.18.3 – CRI-O – CNI: Weave – CSI: CephFS – Ingress Nginx ● Ceph 15.2.3
  • 69.
  • 70. Demo: ansible-collection- kubernetes (cont.) ● Support individual application deployment per namespace, e.g. – Drupal + Apache + PHP-FPM + MariaDB – Jira + Apache + PostgreSQL ● Support HTTPS with Let’s Encrypt
  • 71.
  • 72. Demo: ansible-collection- kubernetes (cont.) ● Fetch source – git clone https://github.com/alvistack/ ansible-collection-kubernetes.git && cd ansible-collection-kubernetes – git submodule update --init –recursive
  • 73. alvistack/ansible-collection- kubernetes (cont.) ● Setup inventory – cp -rfp inventory/default inventory/all – vi inventory/all/hosts
  • 74. alvistack/ansible-collection- kubernetes (cont.) ● Run the playbook – ansible-playbook -i inventory/all/hosts playbooks/coverge.yml
  • 75.
  • 76.
  • 77.
  • 78. Tips & Tricks ● Always Start with Test Cases ● Simple Deployment Goes Molecule + Delegate ● Test Cases Always Goes Molecule + Vagrant + Libvirt + Travis CI ● Create Docker Image After Molecule Test Case by Commit
  • 79. Roadmap ● Migrate everything from Docker to Podman/Buildah/Skopeo ● Handle Kubernetes Addons with Ansible Operator
  • 80. Q&A
  • 81. Contact Us ● Address: Unit 326, 3/F, Building 16W, No.16 Science Park West Avenue, Hong Kong Science Park, Shatin, N.T. ● Phone: +852 3576 3812 ● Fax: +852 3753 3663 ● Email: sales@pantarei-design.com ● Web: http://pantarei-design.com