การสร้างระบบautomation ci/cd pipeline ด้วยopen source...

93
การสร้างระบบ Automation CI/CD Pipeline ด้วย open source Rancher วิทยากร: ธวัช วราไชย / ไกรสุวรรณ หยางทกูร ฝ่ายคอมพิวเตอร์ทางวิศวกรรมศาสตร์ คณะวิศวกรรมศาสตร์ มหาวิทยาลัยสงขลานครินทร์

Upload: others

Post on 21-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

การสรางระบบ Automation CI/CD Pipeline ดวย open source Rancher

วทยากร: ธวช วราไชย / ไกรสวรรณ หยางทกร

ฝายคอมพวเตอรทางวศวกรรมศาสตร คณะวศวกรรมศาสตร

มหาวทยาลยสงขลานครนทร

Page 2: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop agenda

ความรเบองตนเกยวกบระบบ Automation CI/CD

รจกสถาปตยกรรมของ Rancher version 2.1 (RKE)

การตดตง Rancher version 2.1

Workshop 1. เรมตนงาย ๆ ดวยตนแบบทเตรยมไวใหแลว

Workshop 2. เรยนรตามตนแบบและปรบแตงมน

Workshop 3. ทดลองสราง Pine Line ของคณเอง

Discussion and experience sharing

Page 3: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

ความรเบองตนเกยวกบระบบAutomation CI/CD

ความจาเปนตอการใชงานระบบ Automation CI/CD

กระบวนการทางานของระบบ

เครองมอทใชในการสราง

เบองหลงกลไกการทางานของระบบ Automation CI/CD

จะเรมตนสรางระบบงานแบบ Automation ควรเรมตนอยางไร

Page 4: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

ความจาเปนตอการใชงานระบบ Automation CI/CD

ชวยวเคราะหดหนอยนะครบ “หนวยงานใหน จาเปนตองใชกระบวนการ Automation CI/CD” ?.

Operation+ Developer

Aหนวยงาน Bหนวยงาน Cหนวยงาน

Operation

เพลตฟอรมสาหรบการพฒนา

monolithic Microservices

เพลตฟอรมสาหรบการพฒนา

monolithic

เพลตฟอรมสาหรบการพฒนา

Microservices

Developer Developer Developer Operation Developer Developer Developer

Page 5: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

กระบวนการของระบบ Automation CI/CD Pipeline

Continuous Delivery / Continuous Deploy

CDCIContinuous Integration

Page 6: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

เครองมอทใชในการสรางระบบ Automation CI/CD

Drone CI

Concourse CI

Reference https://stackify.com/top-continuous-integration-tools

Page 7: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

เบองหลงการทางานของระบบ Automation CI/CD

http://yaml.orghttps://en.wikipedia.org/wiki/YAML

Execution

(YAML Ain't Markup Language)Initial release 11 May 2001

Page 8: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

จะเรมตนสรางระบบงานแบบ Automation ควรเรมตนอยางไร

1. ควรศกษา ทาความเขาใจและกาหนดขอตกลงรวมกนภายในทม

2. ออกแบบ Workflow ของการพฒนาระบบงานรวมกน

3. เลอกเครองมอทเหมาะสมทสดกบทมของคณ

4. เลอกโครงการทสนใจ มาสก 1-2 โครงการ เพอศกษาและทดสอบกระบวนการ

5. สรปผลการทดสอบและปรบปรงกระบวนการเพอให บรรลเปาหมาย

Page 9: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

ตวอยาง Workflow ของทมพฒนาระบบสารสนเทศของคณะวศวกรรมศาสตร มหาวทยาลยสงขลานครนทร

Productionenvironment

Developenvironment

QA

Deploy

Build

Testing

Run

Feedback

Run

Release upgraded

Operation Developer

Developer

Page 10: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

รจกสถาปตยกรรมของ Rancher version 2.1 (RKE)

RKE, Unified Cluster ManagementHigh-level ArchitectureApplication Workload ManagementRancher tools Pipelines

https://rancher.com

One Platform for Kubernetes Management

Page 11: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

สถาปตยกรรมของ Rancher version 2.1 (RKE)

Google: Kubernetes (K8S)

https://kubernetes.io

https://rancher.com

Page 12: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher 2.1 High-level Architecture

etcdnodes

controlplanenodes

workernodes

Cluster

https://rancher.com/docs/rancher/v2.x/en/overview/architecture

Rancher server components1. Rancher API Server2. Cluster Controller and Agents3. Authentication Proxy

Page 13: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher 2.1 Application Workload Management

https://rancher.com/managing-kubernetes-workloads-with-rancher-2-0

Page 14: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher 2.1 Tools pipelines

https://rancher.com/docs/rancher/v2.x/en/concepts/ci-cd-pipelines

Page 15: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

RequirementsInstallation modeSingle node install

การตดตง Rancher version 2.1

https://rancher.com/docs/rancher/v2.x/en/installation

Page 16: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher version 2.1 Requirements

Operating System

• Ubuntu 16.04 (64-bit)• Red Hat Enterprise Linux 7.5 (64-bit)• RancherOS 1.4 (64-bit)• Windows Server version 1803 (64-bit)

https://rancher.com/docs/rancher/v2.x/en/installation/requirements

Hardware

Deployment Size Clusters Nodes vCPUs RAM

Small Up to 5 Up to 50 4 16GB

Medium Up to 100 Up to 500 8 32GB

Large Over 100 Over 500 Contact RancherSoftware support Docker version

• 17.03.x• 18.06.x• 18.09.x

Page 17: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher 2.1: Installation mode

1. Single Node Install 2. High Availability (HA) Install

1VM / 4 vCPUs / RAM 4 GB

Page 18: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Import image WUNCA39.ova to VirtualBox

WUNCA39.ova

https://bit.ly/2KrnkpV

Page 19: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Virtualbox Network setting

Network setting

Attached to : Bridged Adapter

Name: [Select your network adapter]

Page 20: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Virtualbox start VM and get your IP address

Start VM WUNCA39

User : osboxesPassword: osboxes.org

Check your IP address

ifconfig

Page 21: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Open SSH connection

Open PuTTY program SSH connect

Fill-up your IP address: Open connection

User : osboxesPassword: osboxes.org

Page 22: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher 2.1: single node install with docker command

sudo docker run --name rancher2 --restart=unless-stopped \-d -p 8080:80 -p 8443:443 \-v /data/rancher2:/var/lib/rancher rancher/rancher:latest

Page 23: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Open your web browser for setup Rancher

http://[your ip address]:8080

Example: http://172.13.133.148:8080

Set new password for admin user

Click “Continue”

Page 24: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Open your web browser for setup Rancher

Click “Save URL”

Page 25: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Open your web browser for setup Rancher

Welcome to Rancher!

Click “Got it”

Page 26: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Add Cluster

Select “CUSTOM”

Example wunca39

Then click “Next”

Page 27: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Add Cluster

Set Node Role

• Etcd

• Control plane

• worker

Click “copy to clipboard”

Page 28: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Install Rancher agent node

Paste code from clipboard to SSH terminal

Enter for run docker command

Page 29: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Check your status in Add Cluster

“1 new node has registered”

Click “Done”

Page 30: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Wait for Rancher setup system workload

Click menu wunca39 > system

Check for “green color active”

status

Wait for system workload is active

Successfully are system workload

activated

Page 31: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 1. เรมตนงาย ๆ ดวยตนแบบทเตรยมไวใหแลว

Github fork startup template projectRancher add repository and authorize Github accountThe first run manual pipeline CI/CDSee your result

Page 32: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Github fork startup template project

1. Github login

2. Fork repository from

https://github.com/vthawat/wunca39

Page 33: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

1. Click from menu

wunca39 > default

2. Click “Pipelines”

3. Click “Configure Repositories”

Page 34: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

1. Click from menu

wunca39 > default

2. Click “Pipelines”

3. Click “Configure Repositories”

4. Click “Authorize & Fetch Your Own Repository”

5. Click “Config Now”

Page 35: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

Follow step from Setup a githubapplication

Page 36: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

Step 1. add new application from link https://github.com/settings/developers

Page 37: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

Step 2. Fill-up form for Register a new OAuth application

This is example please see instruction from your Rancher screen

Then click “Register application”

Page 38: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

Copy Client ID and Client Secret from your Github application

Then click “Authenticate”

Page 39: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add repository for manage

Click “Authorize”

Page 40: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher enable repository for run CI/CD pipeline

Click Enabled for repository wunca39.git

Then click “Done”

Page 41: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

The first run manual pipeline CI/CD

Page 42: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

The first run manual pipeline CI/CD

Wait for pipeline execution

see log detail on pipeline step

Page 43: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

The first run manual pipeline CI/CD

The pipeline execution success all step display green color

Page 44: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

See your result the CI/CD startup template

Page 45: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation
Page 46: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 2. เรยนรตามตนแบบและปรบแตงมน

How Pipelines Work on Rancher version 2.1How to customize startup template

Page 47: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

How Pipelines Work on Rancher version 2.1

https://rancher.com/docs/rancher/v2.x/en/tools/pipelines/#how-pipelines-work

1

2

3

Page 48: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

How to customize startup template

Important files of Rancher CI/CD pipeline

.rancher-pipeline.yaml -- rancher pipeline script

Dockerfile -- docker build image script

Deployment.yaml -- rancher deployment script

1

2

3

Page 49: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher pipeline stages

https://rancher.com/docs/rancher/v2.x/en/tools/pipelines

Build Publish Deploy1 2 3

Page 50: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

.rancher-pipeline.yaml

How to customize startup template

1

Page 51: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Build stage

Build stages

- runScriptConfig:

image: [image for build source code]

shellScript: [use shell command from image define]

Example:

image: alpine

shellScript: |-

mkdir ./test

echo ‘hello wunca39’ > ./test/test.txt

Page 52: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Publish stage

Publish stages

- publishImageConfig:

dockerfilePath: [docker source for build image]

buildContext: . [use option command for docker build]

tag: [use command for docker tag]

Example:

dockerfilePath : ./Dockerfile

buildContext : .

tag: vthawat/wunca39:version-1

Page 53: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Deploy stage

Deploy stages

- applyYamlConfig:

path: [rancher source deployment config]

Example:

path : ./deployment.yaml

Page 54: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Dockerfile

How to customize startup template

2

Page 55: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Dockerfile

FROM [base image for docker build]

RUN [use command reference on image from]

COPY [copy file local to build image ]

CMD [use command when container start]

EXPOSE [use port number for connection]

Example:

FROM nginx

COPY /sample-html /usr/share/nginx/html

EXPOSE 80

https://docs.docker.com/develop/develop-images/dockerfile_best-practices

Page 56: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

deployment.yaml

How to customize startup template

3

Page 57: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

deployment.yaml

kind: Service kind: Deployment

metadata:

name: hello-service

labels:

app:hello

spec:

port: 80

https://kubernetes.io/docs/getting-started-guides/ubuntu/rancher

metadata:

name: deploy-hello

labels:

app:hello

spec:

replicas: 3

Page 58: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 2.1 Pipeline CI/CD trigger

Pipeline CI/CD trigger configurationTesting git push for trigger eventCheck your result

Page 59: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Pipeline CI/CD trigger configuration

Pipeline trigger type

1 Branch 2 Event

webhook

Git CLI

- Master

- Develop

- pull request- push- tag

Page 60: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Github web hook don’t work in localhost or LAN IP address

https://developer.github.com/webhooks/configuring

web hook

https://172.31.133.148:8080Rancher Server

Using ngrokForwarding https://7e9ea9dc.ngrok.io -> 172.31.133.148:8080

Rancher server https://7e9ea9dc.ngrok.io

Page 61: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Using https://ngrok.com

Page 62: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Setup ngrok

1. Sign up new account

https://dashboard.ngrok.com/user/signup

2. Open SSH terminal

wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip

unzip ngrok-stable-linux-amd64.zip

./ngrok authtoken <YOUR_AUTH_TOKEN>

./ngrok http <YOUR HOST IP ADDRESS>:8080

3. Copy url from ngrok generate URL forwarding

Example: https://6c595d35.ngrok.io

Page 63: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher settings server-url

Page 64: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher settings server-url

Page 65: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Git hub add webhooks

Payload URL:

https://e08ac305.ngrok.io/hooks

Content type: application/json

Secret: dfgkp994

Example

Page 66: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Check your git hub repository settings Webhooks

Page 67: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher pipeline configure repositories

Page 68: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Configure repositories Disable and Enable toggle

Page 69: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Testing git push for trigger event

1. Git clone your repository

2. Modify source code

./sample-html/index.html

3. Git commit

4. Git push

Page 70: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Testing git push for trigger event

Page 71: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Testing git push for trigger event

Pipeline begin process automatic when git push event

Page 72: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 2.2 Deploy with Ingrees

About IngressConfiguration deployment.yaml

Page 73: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

About Ingress

https://kubernetes.io/docs/concepts/services-networking/ingress

Kubernetes engine

Pod service A

Pod service B

Ingress controller

Internet

wunca39.workshop.io

demo.workshop.comUser

Version 2.1

Page 74: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Configuration deployment.yaml

• remove comment line #

• Edit

host wunca38.[your ingress controller ip].nip.io

• Sample domain with wildcard DNS for any IP Address

• Save

• Git commit

• Git push

Page 75: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Wait pipeline process

Page 76: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

See detailed log pipeline deploy step

Page 77: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

See your Workloads > Load balancing

Ingress created wunca39 > devstarter-service

Page 78: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Check your result

Page 79: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 2.3 Run pipeline example-react

Learn for build and testing pipeline CI/CD

Page 80: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Learn for build and testing pipeline CI/CD

Fork example-react project

https://github.com/vthawat/example-react

Deploy example-react with Ingress

http://example-react.[your ip address].xip.io

1

2

Page 81: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Check your result

Page 82: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 2.4 Use external docker registry

About docker registryCreate new repository on docker hubPipeline configuration use external docker registry

Page 83: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher Pipelines default use internal private registry

https://rancher.com/docs/rancher/v2.x/en/tools/pipelines/#how-pipelines-work

1

2

3

Page 84: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

About docker registry

Public Registry

Docker image

Docker image

Docker image

Docker pull Docker pull

Docker push Docker push

Authentication

Private Registry

Docker image

Docker image

Docker image

Authenticationhub.docker.com gitlab.com

treescale.com

Page 85: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Create new repository on hub.docker.com

1. Sign-in https://hub.docker.com

2. Create Repository

3. Fill-up repository name and shot description

4. Click “Create”

Page 86: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add registry

Page 87: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Rancher add registry

1. Fill-up Name

2. Address select DockerHub

3. Fill-up username/password Docker hub account

4. Click “Save”

Page 88: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Configuration file .rancher-pipeline.yaml

Edit on line 12

tag: [dockerhub username]/wunca39:version-${CICD_EXECUTION_SEQUENCE}

Remove comment on line 14-15

pushRemote: true

registry: index.docker.io

Page 89: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Git push and wait for Pipeline execution

Page 90: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Workshop 3. ทดลองสราง Pine Line ของคณเอง

Page 91: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Create and design your pipeline CI/CD

1 2 3 4

RKE

ตองเขาใจกระบวนการขนตอนใน

การ build docker image ใหรองรบ

การทางานของ App หรอ Services

ตองเขาใจกระบวนการ

ขนตอนในการ test และ

build source code

ตองเขาใจกระบวนการขนตอนใน

การ deploy container ใหทางาน

รวมกนมากกวา 1 container

ตองตงเปาหมายทจะ

พฒนาอะไร เชน

Services , Application

เปนตนและเลอกภาษาท

ใชในการพฒนาให

เหมาะสมกบสงทจะ

พฒนาใหมากทสด

Page 92: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Discussion and experience sharing

Page 93: การสร้างระบบAutomation CI/CD Pipeline ด้วยopen source …wunca.uni.net.th/wunca_regis/wunca39_doc/28/014-.Automation-CICD.pdfการสร้างระบบAutomation

Thank [email protected]://ecs.eng.psu.ac.th

ฝายคอมพวเตอรทางวศวกรรมศาสตร คณะวศวกรรมศาสตร

มหาวทยาลยสงขลานครนทร