operators with build kubernetes ansible no go? automates slide...red hat® openshift® is a...

27
No Go? Build Kubernetes Operators with Ansible Raed Soliman Solutions Architect, Management Tiger Team

Upload: others

Post on 22-May-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

No Go?Build Kubernetes Operators with AnsibleRaed SolimanSolutions Architect, Management Tiger Team

Page 2: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Building Kubernetes Operators with Ansible

What Are Kubernetes Operators?

Why Build Operators with Ansible?

Developing Your First Operator with Ansible

Next Steps

Page 3: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

What is Kubernetes?

An open source orchestration system for implementing a microservices architecture as containerized applications run and coordinated across a cluster of nodes.

Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes at its core.

Kubernetes Operators with Ansible

Page 4: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Manage how containerized apps interact with other apps or the outside world

Run distributed systems resiliently across a cluster of nodes

Perform health checks

Kubernetes Operators with Ansible

What does Kubernetes help do?

Scale your services up or down

Perform graceful rolling updates

Networking and routing of traffic

Manages ephemeral and persistent storage volumes

Page 5: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Kubernetes Operators with Ansible

apiVersion: v1kind: Podmetadata: name: example-app labels: app: example-appspec: containers: - name: example image: companyname/example:v1.2.0 ports: - containerPort: 8000

apiVersion: v1kind: Servicemetadata: name: example-servicespec: selector: app: example-app ports: - protocol: TCP port: 80 targetPort: 8000

Kubernetes Object Definitions

Page 6: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Extending Kubernetes with aCustom Resource Definition (CRD)

apiVersion: cache.example.com/v1alpha1kind: Memcachedmetadata: name: example-memcachedspec: size: 3

Custom resources definition (CRD) is a powerful feature introduced into Kubernetes which enables users to add their own/custom objects to the Kubernetes cluster and use it like any other native Kubernetes objects.

Kubernetes Operators with Ansible

Page 7: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Ansible fits naturally into a Kubernetes environment

Page 8: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Kubernetes and Ansible

Kubernetes Operators with Ansible

● Both help make hard things easier through automation and orchestration

● Both are very active and widely used open source projects

● Both have vibrant communities working to solve common problems

● Both use YAML to describe the desired state of the world

Page 9: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Kubernetes Operators with Ansible

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 }}”

YAML to describe the desired state of the worldKUBERNETES/KUBECTL ANSIBLE

Page 10: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Templating Kubernetes resource definitions with Ansible

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

Page 11: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

What are Kubernetes Operators?

Page 12: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Stateless is easy, Stateful is hard

Page 13: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

● Encode human operational knowledge

● Automatically patch, upgrade, recover, and tune container-based apps and services

● Kubernetes-native

● Purpose-built for a specific application or service

● Enable “day 2” management

Kubernetes Operators with Ansible

Kubernetes OperatorsOperators simplify management of complex applications on Kubernetes

Page 14: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

K8S API CUSTOM RESOURCE & MY

APP STATE

WATCH EVENTS

RECONCILE MY K8S APPLICATION

The Operator Pattern

Controller

Kubernetes Operators with Ansible

Page 15: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Why build Operators with Ansible?

Page 16: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Making it easier to deploy and manage Kubernetes apps in an Ansible-native way

Ansible Operator SDK

Kubernetes Operators with Ansible

Use the Operator SDK to create a new skeleton

Operator.

operator-sdk new Add Ansible Content

Use Ansible Roles and playbooks to manage

lifecycle events for your containerized applications.

operator-sdk build

Use the Operator SDK to build and deploy your

Operator to Kubernetes.

Page 17: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

EXISTING SKILLS & ECOSYSTEM

Same tried & trusted Ansible tooling

Utilize existing skills

Supports cloud-native & traditional IT automation with one simple language

Leverages vibrant existing ecosystem

Why build Operators with Ansible?

LOWER BARRIER OF ENTRY

No programming required

Faster iterations and easier maintenance

Declarative state definitions like K8s

Templating of resources

Abstraction layer & helpers that reduces necessary K8s API experience

Kubernetes Operators with Ansible

Page 18: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Operator capability level

Kubernetes Operators with Ansible

Phase I Phase II Phase III Phase IV Phase V

Basic Install

Automated application provisioning and configuration management

Seamless Upgrades

Patch and minor version upgrades supported

Full Lifecycle

App lifecycle, storage lifecycle (backup, failure recovery)

Deep Insights

Metrics, alerts, log processing and workload analysis

Auto Pilot

Horizontal/vertical scaling, auto config tuning, abnormal detection, scheduling tuning

Page 19: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

K8S API MY K8S APPLICATION

K8s Operator with Ansible

WATCH FILE

PLAYBOOK OR ROLE

OPERATOR SDK

BINARY

Design overview

Kubernetes Operators with Ansible

CUSTOM RESOURCE & MY

APP STATE

Page 20: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Anatomy of Ansible-enabled Operator image

your Operator image

Ansible Role

Ansible Rolewatches.yaml

base Ansible Operator SDK image

Operator SDK Binaryansible-runner

AnsiblePython + Libraries

Kubernetes Operators with Ansible

Page 21: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

K8S API

CUSTOM RESOURCE

MY K8S APPLICATION

automatically updates resource

status

OPE

RATO

R SD

K BI

NARY

K8s Operator with Ansible

WATCHES.YML

ANSIBLERUNNER

executes & reports

Reconciliation with K8s Cluster

event monitoring

manages

Kubernetes Operators with Ansible

INFORMER

REVERSE PROXY

reads

Page 22: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Developing your first Operator with Ansible

Page 23: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Developing your first Operator with Ansible

● Initialize Your Operator With Ansible○ $ operator-sdk new foo-operator

--api-version=cache.example.com/v1alpha1 --kind=Foo --type=ansible

● Automate With Ansible○ Create new roles and playbooks or reuse an existing one

● Define a watches file○ Map a Kubernetes object to your Ansible content

● Build Your Operator○ $ operator-sdk build foo-operator:v0.0.1

● Deploy Your Operator to a Kubernetes Cluster

Kubernetes Operators with Ansible

Page 24: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Explore Operators

OperatorHub.io is a home for the Kubernetes community to share Operators.

Find an existing Operator or list your own today.

Kubernetes Operators with Ansible

Page 25: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

Get started with Ansible: Get started with Operators:ansible.com/get-started

ansible.com/community

github.com/operator-framework/getting-started

ansible.com/operators

Next steps

Page 26: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

etcd OperatorA great example of a sophisticated Kubernetes Operator using Ansible:github.com/water-hole/etcd-ansible-operator

Memcached OperatorSimple walkthrough for building an Operators using the Ansible Operator SDK and Kubernetes CRDs github.com/operator-framework/operator-sdk-samples/tree/master/memcached-operator

More resources

Page 27: Operators with Build Kubernetes Ansible No Go? Automates Slide...Red Hat® OpenShift® is a comprehensive enterprise-grade application platform built for containers with Kubernetes

linkedin.com/company/red-hat

youtube.com/user/RedHatVideos

facebook.com/redhatinc

twitter.com/RedHat

Thank you