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

Post on 21-Jun-2020

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

Operation+ Developer

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

Operation

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

monolithic Microservices

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

monolithic

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

Microservices

Developer Developer Developer Operation Developer Developer Developer

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

Continuous Delivery / Continuous Deploy

CDCIContinuous Integration

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

Drone CI

Concourse CI

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

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

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

Execution

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

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

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

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

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

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

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

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

Productionenvironment

Developenvironment

QA

Deploy

Build

Testing

Run

Feedback

Run

Release upgraded

Operation Developer

Developer

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

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

https://rancher.com

One Platform for Kubernetes Management

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

Google: Kubernetes (K8S)

https://kubernetes.io

https://rancher.com

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

Rancher 2.1 Application Workload Management

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

Rancher 2.1 Tools pipelines

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

RequirementsInstallation modeSingle node install

การตดตง Rancher version 2.1

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

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

Rancher 2.1: Installation mode

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

1VM / 4 vCPUs / RAM 4 GB

Import image WUNCA39.ova to VirtualBox

WUNCA39.ova

https://bit.ly/2KrnkpV

Virtualbox Network setting

Network setting

Attached to : Bridged Adapter

Name: [Select your network adapter]

Virtualbox start VM and get your IP address

Start VM WUNCA39

User : osboxesPassword: osboxes.org

Check your IP address

ifconfig

Open SSH connection

Open PuTTY program SSH connect

Fill-up your IP address: Open connection

User : osboxesPassword: osboxes.org

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

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”

Open your web browser for setup Rancher

Click “Save URL”

Open your web browser for setup Rancher

Welcome to Rancher!

Click “Got it”

Add Cluster

Select “CUSTOM”

Example wunca39

Then click “Next”

Add Cluster

Set Node Role

• Etcd

• Control plane

• worker

Click “copy to clipboard”

Install Rancher agent node

Paste code from clipboard to SSH terminal

Enter for run docker command

Check your status in Add Cluster

“1 new node has registered”

Click “Done”

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

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

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

Github fork startup template project

1. Github login

2. Fork repository from

https://github.com/vthawat/wunca39

Rancher add repository for manage

1. Click from menu

wunca39 > default

2. Click “Pipelines”

3. Click “Configure Repositories”

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”

Rancher add repository for manage

Follow step from Setup a githubapplication

Rancher add repository for manage

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

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”

Rancher add repository for manage

Copy Client ID and Client Secret from your Github application

Then click “Authenticate”

Rancher add repository for manage

Click “Authorize”

Rancher enable repository for run CI/CD pipeline

Click Enabled for repository wunca39.git

Then click “Done”

The first run manual pipeline CI/CD

The first run manual pipeline CI/CD

Wait for pipeline execution

see log detail on pipeline step

The first run manual pipeline CI/CD

The pipeline execution success all step display green color

See your result the CI/CD startup template

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

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

How Pipelines Work on Rancher version 2.1

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

1

2

3

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

Rancher pipeline stages

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

Build Publish Deploy1 2 3

.rancher-pipeline.yaml

How to customize startup template

1

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

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

Deploy stage

Deploy stages

- applyYamlConfig:

path: [rancher source deployment config]

Example:

path : ./deployment.yaml

Dockerfile

How to customize startup template

2

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

deployment.yaml

How to customize startup template

3

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

Workshop 2.1 Pipeline CI/CD trigger

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

Pipeline CI/CD trigger configuration

Pipeline trigger type

1 Branch 2 Event

webhook

Git CLI

- Master

- Develop

- pull request- push- tag

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

Using https://ngrok.com

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

Rancher settings server-url

Rancher settings server-url

Git hub add webhooks

Payload URL:

https://e08ac305.ngrok.io/hooks

Content type: application/json

Secret: dfgkp994

Example

Check your git hub repository settings Webhooks

Rancher pipeline configure repositories

Configure repositories Disable and Enable toggle

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

Testing git push for trigger event

Testing git push for trigger event

Pipeline begin process automatic when git push event

Workshop 2.2 Deploy with Ingrees

About IngressConfiguration deployment.yaml

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

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

Wait pipeline process

See detailed log pipeline deploy step

See your Workloads > Load balancing

Ingress created wunca39 > devstarter-service

Check your result

Workshop 2.3 Run pipeline example-react

Learn for build and testing pipeline CI/CD

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

Check your result

Workshop 2.4 Use external docker registry

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

Rancher Pipelines default use internal private registry

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

1

2

3

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

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”

Rancher add registry

Rancher add registry

1. Fill-up Name

2. Address select DockerHub

3. Fill-up username/password Docker hub account

4. Click “Save”

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

Git push and wait for Pipeline execution

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

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

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

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

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

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

Discussion and experience sharing

Thank youthawat.va@psu.ac.thhttps://ecs.eng.psu.ac.th

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

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

top related