Top Banner
Operators Robert Bohne SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1
30

Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Aug 01, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Operators

Robert BohneSR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFTTwitter: @RobertBohne

1

Page 2: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Operators are automated software managers that deal with

installation and lifecycle of Kubernetes applications

Page 3: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

OperatorHub in OpenShift

RED HAT OPENSHIFT 4

3

The embedded registry for Community and Certified Operators from Red Hat and Partners, tested and verified on OpenShift 4

Page 4: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

1. Application-specific custom controller2. Custom Resource Definition (CRD)

Page 5: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Application-Specific Controller

Page 6: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Custom Resource Definition (CRD)

kind: ProductionReadyDatabase

apiVersion: database.example.com/v1alpha1

metadata:

name: my-production-ready-database

spec:

clusterSize: 3

readReplicas: 2

version: v4.0.1

[...]

Page 7: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Custom Resource (CR)

{

}

Page 8: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Demo

Page 9: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Custom Resource

MyApplicationState

k8s API

Controller

Watch Events Reconciliation

My Application

Kubernetes Resources for My App

Operator Pattern

Page 10: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

https://github.com/operator-framework

Page 11: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle
Page 12: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle
Page 13: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle
Page 14: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Custom Resource

MyApplicationState

k8s API

Controller

Watch Events Reconciliation

My Application

Kubernetes Resources for My App

Operator Pattern

Page 15: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

You don’t need to learn to write an Operator!

Page 16: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle
Page 17: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle
Page 18: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

k8s YAML

apiVersion: v1kind: ConfigMapmetadata: name: foo namespace: defaultdata: color: red

---- name: create foo configmap k8s: definition: apiVersion: v1 kind: ConfigMap metadata: name: foo namespace: default data: color: “{{ color }}”

Ansible Task

Page 19: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

k8s Module + Jinja2 Templates

---- name: create foo configmap k8s: definition: "{{ lookup('template', '/foo.yml') | from_yaml }} "

Page 20: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Custom Resource

MyApplicationState

k8s API

Ansible Operator

Operator-SDK

Ansible Role

My Application

Kubernetes Resources for My App

Ansible Operator

File Mapping

Ansible k8s modules will be used to create resources in kubernetes

Page 21: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

What you need to create an Ansible Operator

● A CustomResourceDefinition (CRD)

● An Ansible Playbook or Role

● A mapping from CRD to Ansible playbook / roles

● operator-sdk

Page 22: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Create the Operator with the SDK

$ operator-sdk new memcached-operator \ --api-version=cache.example.com/v1alpha1 \ --kind=Memcached --type=ansible

Creates:

● Ansible Role● Mapping File (watches.yaml)● Custom Resource Definition● Deploy manifest for the new Operator

Page 23: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Custom Resource (CR)

apiVersion: <Group/Version>kind: <kind>metadata: name: <name>spec: <key>: <value> ….status: <key>: <value> ….

Ansible Operator

Status will be a generic status defined by the operator. This will use ansible runner output to generate meaningful output for the user.

Spec values will be translated to Ansible extra vars.

Page 24: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Ansible Role

Create a Role that deploys and manages your application

memcached/├── defaults│ └── main.yml├── files├── handlers│ └── main.yml├── meta│ └── main.yml├── README.md├── tasks│ └── main.yml├── templates├── tests│ ├── inventory│ └── test.yml└── vars └── main.yml

Page 25: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Mapping between CRDs and Ansible

Maps a Group Version Kind (GVK) to a role or playbook.

# watches.yaml---- version: v1alpha1 - group: cache.example.com kind: Memcached playbook: /path/to/playbook

Page 26: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Build the Operator with the SDK

$ operator-sdk build memcached-operator:v0.0.1

Creates:

● A Dockerfile that creates the Operator● Builds the container on top of ansible-runner image

Page 27: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Demo

Page 28: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Try it yourself!

learn.openshift.com/ansibleop

Page 29: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Resource

https://github.com/operator-framework

https://coreos.com/operators/

https://github.com/operator-framework/awesome-operators

https://coreos.com/blog/introducing-operator-framework

https://learn.openshift.com/operatorframework/

Page 30: Operators - OPENSHIFT ANWENDER...SR. SPECIALIST SOLUTION ARCHITECT | OPENSHIFT Twitter: @RobertBohne 1. Operators are automated software managers that deal with installation and lifecycle

Danke!