automated image builds in openshift and kubernetes

43
Automated Image Builds in OpenShift and Kubernetes Graham Dumpleton - Red Hat @GrahamDumpleton

Upload: graham-dumpleton

Post on 21-Apr-2017

750 views

Category:

Internet


6 download

TRANSCRIPT

Page 1: Automated Image Builds in OpenShift and Kubernetes

Automated Image Builds in OpenShift and

KubernetesGraham Dumpleton - Red Hat

@GrahamDumpleton

Page 2: Automated Image Builds in OpenShift and Kubernetes

OpenShift Stack

Page 3: Automated Image Builds in OpenShift and Kubernetes

Access and Control

Page 4: Automated Image Builds in OpenShift and Kubernetes

Namespace

Page 5: Automated Image Builds in OpenShift and Kubernetes

Pods

Page 6: Automated Image Builds in OpenShift and Kubernetes

Persistent Volumes

Page 7: Automated Image Builds in OpenShift and Kubernetes

Networking

Page 8: Automated Image Builds in OpenShift and Kubernetes

Deployments

Page 9: Automated Image Builds in OpenShift and Kubernetes

Builds

Page 10: Automated Image Builds in OpenShift and Kubernetes

Docker Build

Page 11: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: BuildConfig metadata: name: myimage spec: strategy: type: Docker dockerStrategy: from: kind: ImageStreamTag name: centos:7 source: type: Git git: uri: https://github.com/demo/myimage.git output: to: kind: ImageStreamTag name: myimage:latest

BuildConfig (Docker Strategy)

Page 12: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: ImageStream metadata: name: centos spec: tags: - from: kind: DockerImage name: centos:7 name: 7 apiVersion: v1 kind: ImageStream metadata: name: myimage

ImageStream(s)

Page 13: Automated Image Builds in OpenShift and Kubernetes

Loading the Resources

oc create -f myimage-build-configuration.yaml

Page 14: Automated Image Builds in OpenShift and Kubernetes

Short Cut for Creating Docker Build

oc new-build https://github.com/demo/myimage.git

Page 15: Automated Image Builds in OpenShift and Kubernetes

Manually Trigger a Rebuild

oc start-build myimage

Page 16: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: BuildConfig metadata: name: myimage spec: strategy: type: Docker … source: type: Git git: uri: https://github.com/demo/myimage.git triggers: - type: ConfigChange - type: ImageChange - type: GitHub github: secret: kkDMDki2O40wtqDd_cxA

Build Triggers

Page 17: Automated Image Builds in OpenShift and Kubernetes

Build ConfigChange Trigger

oc set env bc/myimage --env DEBUG=1

Page 18: Automated Image Builds in OpenShift and Kubernetes

ImageChange Trigger

oc import-image centos:7

Page 19: Automated Image Builds in OpenShift and Kubernetes

GitHub Trigger

Page 20: Automated Image Builds in OpenShift and Kubernetes

Deployment

Page 21: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: DeploymentConfig metadata: name: myimage spec: replicas: 1 selector: app: myimage template: metadata: labels: app: myimage spec: containers: - image: 172.30.240.125:5000/demo/myimage:latest name: myimage ports: - containerPort: 8080 protocol: TCP

Deployment Configuration

Page 22: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: Service metadata: name: myimage spec: ports: - name: 8080-tcp port: 8080 protocol: TCP targetPort: 8080 selector: app: myimage

Service

Page 23: Automated Image Builds in OpenShift and Kubernetes

Short Cut for Deploy

oc new-app myimage

Page 24: Automated Image Builds in OpenShift and Kubernetes

Short Cut for Build/Deploy

oc new-app https://github.com/demo/myimage.git

Page 25: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: DeploymentConfig metadata: name: myimage spec: … triggers: - type: ConfigChange - type: ImageChange imageChangeParams: containerNames: - myimage from: kind: ImageStreamTag name: myimage:latest namespace: demo

Deployment Triggers

Page 26: Automated Image Builds in OpenShift and Kubernetes

Deployment ConfigChange Trigger

oc set env dc/myimage --env DEBUG=1

Page 27: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: Route metadata: name: myimage spec: host: "" port: targetPort: 8080-tcp to: name: myimage

Route

Page 28: Automated Image Builds in OpenShift and Kubernetes

Short Cut for Exposing Service

oc expose svc/myimage

Page 29: Automated Image Builds in OpenShift and Kubernetes

Source Build

Page 30: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: BuildConfig metadata: name: myapp spec: strategy: type: Source sourceStrategy: from: kind: ImageStreamTag namespace: openshift name: python:2.7 source: type: Git git: uri: https://github.com/demo/myapp.git output: to: kind: ImageStreamTag name: myapp:latest

BuildConfig (Source Strategy)

Page 31: Automated Image Builds in OpenShift and Kubernetes

apiVersion: v1 kind: ImageStream metadata: name: python namespace: openshift spec: tags: - from: kind: DockerImage name: centos/python-27-centos7:latest name: "2.7"

Builder ImageStream

Page 32: Automated Image Builds in OpenShift and Kubernetes

Short Cut for Source Build/Deploy

oc new-app python:2.7~https://github.com/demo/myapp.git

Page 33: Automated Image Builds in OpenShift and Kubernetes

S2I Execution Steps

Page 34: Automated Image Builds in OpenShift and Kubernetes

S2I Application Image

cat /tmp/files.tar | docker run -i --name mybuild \ centos/python-27-centos7:latest \ bash -c "tar -C /tmp -xf - && \ /usr/libexec/s2i/bin/assemble"

docker commit mybuild myapp:latest

Page 35: Automated Image Builds in OpenShift and Kubernetes

Assemble Script

#!/bin/bash WARPDRIVE_APP_ROOT=/opt/app-root WARPDRIVE_SRC_ROOT=$WARPDRIVE_APP_ROOT/srccp -Rf /tmp/src/. $WARPDRIVE_SRC_ROOT rm -rf /tmp/src warpdrive build chmod -Rf g+w $WARPDRIVE_SRC_ROOT || true

Page 36: Automated Image Builds in OpenShift and Kubernetes

Running Image

docker run -p 8080:8080 myapp

Page 37: Automated Image Builds in OpenShift and Kubernetes

Run Script

#!/bin/bash exec warpdrive start

Page 38: Automated Image Builds in OpenShift and Kubernetes

Using S2I Outside of OpenShift

s2i build https://github.com/demo/myapp.git \ centos/python-27-centos7:latest myapp docker run -p 8080:8080 myapp

Page 39: Automated Image Builds in OpenShift and Kubernetes

Source to Image Project

• https://github.com/openshift/source-to-image

Page 40: Automated Image Builds in OpenShift and Kubernetes

Demo/Questions

Page 41: Automated Image Builds in OpenShift and Kubernetes

OpenShift Resources

• OpenShift Originhttps://www.openshift.org

• OpenShift Enterprise/Dedicated https://www.openshift.com

• OpenShift Commonshttp://commons.openshift.org

Page 42: Automated Image Builds in OpenShift and Kubernetes

Try OpenShift

• OpenShift TestDrive Lab on Amazon Web Services https://www.openshift.com/dedicated/test-drive.html

• All-In-One Vagrant VM box https://www.openshift.org/vm/

• Free Red Hat Container Development Kit (CDK) http://developers.redhat.com/products/cdk/overview/

Page 43: Automated Image Builds in OpenShift and Kubernetes