1 of 45

Megan O’Keefe and Shabir Abdul Samadh

Google Cloud

YAML Your Cloud!

Managing Cloud-Hosted Resources from Kubernetes

2 of 45

Hello!

Megan O’Keefe

Developer Relations, Google Cloud

@askmeegs

Shabir Abdul Samadh

Developer Relations, Google Cloud

@shabirmean

3 of 45

On Deck

  1. What is the Kubernetes Resource Model (KRM)?

  • Why manage cloud-hosted resources from K8s?

  • How to manage cloud-hosted resources from K8s?

4 of 45

What is the

Kubernetes Resource Model (KRM)?

5 of 45

The Kubernetes API Server

API Server

etcd

cloud-

controller-

manager

kube-

scheduler

kube-

controller-

manager

cloud provider

Control Plane Node

kubelet

kube

proxy

container

runtime

Node

kubelet

kube

proxy

container

runtime

Node

kubelet

kube

proxy

container

runtime

Node

6 of 45

The Declarative Model

Declarative = API objects express intent

Controllers = loop to make your desired state match the actual running state

observe

diff

act

7 of 45

The Kubernetes Resource Model

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

namespace: my-app

labels:

app: nginx

spec:

containers:

- name: nginx

image: nginx:1.14.2

args: [“-port=8080”]

ports:

containerPort: 8080

……

status:

……

Metadata

Desired state

Observed state �(added/updated by the K8s system)

8 of 45

The Kubernetes Resource Model

The Kubernetes API can also be extended using Custom Resource Definitions (CRDs) with custom controllers.

Controllers that install + upgrade applications inside K8s

are called operators.

9 of 45

Why manage hosted resources with KRM?

10 of 45

Ways to interact with a cloud provider

Cloud Console

1st party command line

Client Libraries

3rd-party tools

eg. Terraform

kubectl

K8s client libraries

Cloud

APIs

Kubernetes API

11 of 45

K8s + hosted resources is hard.

Different APIs, different resource models + formats

Different paradigms (imperative vs. declarative, client-side vs. server side)

Different authentication (IAM / RBAC) systems

Add multiple cloud providers, and the complexity multiplies.

IAM: Identity and Access Management

RBAC: Role Based Access Control

12 of 45

What if...

Cloud

Console

1st party command line

Client

Libraries

3rd-party tools

eg. Terraform

kubectl

K8s client libraries

Kubernetes

API

Cloud

APIs

13 of 45

The Kubernetes Resource Model

Tightly coupled tool ecosystems

KRM ecosystem

Decoupled data model

14 of 45

Unifying resources with the K8s API

Git Repo

Cloud

Resources

API Server

In-Cluster Controllers

In-Cluster Resources

Cloud

Controllers

15 of 45

How to manage hosted resources with KRM?

16 of 45

YAML your cloud, in 4 steps!

  1. Choose your tools.
  2. Write YAML.
  3. Figure out where to put the YAML.
  4. Set up guardrails.

17 of 45

First-party cloud controllers

18 of 45

AWS Controllers for Kubernetes (ACK)

A set of open-source Kubernetes controllers to manage hosted AWS resources

Separate controllers per resource type (EC2, S3, etc.)

Can run inside AWS Elastic Kubernetes Service (EKS)

19 of 45

How ACK works (S3)

  1. Install the ACK S3 controller to an EKS cluster with Helm
  2. Give ACK permissions to create S3 resources
  3. Write + apply an S3 bucket YAML
  4. Deploy an app that uses that S3 bucket

20 of 45

EKS

Cymbal

Ads

S3

Bucket

ACK

21 of 45

Demo:

Managing AWS-hosted resources with AWS Controllers for Kubernetes

22 of 45

Google Cloud Config Connector

Like ACK, Config Connector is an in-cluster controller to manage cloud resources (this time, for Google Cloud).

Unlike ACK, Config Connector is a first-party product.

Unlike ACK, Config Connector operates as a single controller for many GCP resources.

23 of 45

How Config Connector Works

  1. Install Config Connector on a GKE cluster
  2. Give Config Connector permissions to create hosted GCP resources
  3. Write Config Connector YAML to create hosted resources
  4. Apply the YAML to the GKE cluster
  5. Config Connector controllers lifecycle the hosted resources

24 of 45

How Config Connector Works

GKE

Config

Connector

25 of 45

How Config Connector Works

apiVersion: redis.cnrm.cloud.google.com/v1beta1

kind: RedisInstance

metadata:

name: redis-cart

namespace: config-connector-resources

spec:

displayName: "Cymbal Shops Redis Cart"

region: us-central1

redisVersion: "REDIS_5_0"

tier: BASIC

memorySizeGb: 1

26 of 45

How Config Connector Works

GKE

Config

Connector

Memorystore

27 of 45

Demo:

Managing Google-Cloud Hosted Resources with Config Connector

28 of 45

Setting guardrails for cloud KRM

“Only cluster admins can create Memorystore instances.”

➡️ Kubernetes RBAC

“Memorystore instances must use Redis v5.

➡️ ??

29 of 45

OpenPolicyAgent Gatekeeper

A policy “gate” for a Kubernetes cluster.

Runs as an admission controller (before resources can get to the API server)

Can be configured with custom policies on specific resource types, both Kubernetes and custom (Cloud)

30 of 45

Benefits of OPA Gatekeeper

Automate policy enforcement for Cloud resources before the resources get created

Stay in compliance with industry- or geo-specific regulations

Policies defined as K8s CRDs, can be stored in Git + approved, audited

Accelerate developer velocity + feedback loop (can check policies during CI/CD, too!)

31 of 45

How to use Gatekeeper

  1. Write a Constraint Template (abstract policy template)
  2. Write a Constraint (concrete policy)
  3. Apply those resources to the cluster
  4. Gatekeeper will automatically enforce the policy for all incoming resources, blocking out-of-policy resources.

32 of 45

How to use Gatekeeper

GKE

Config

Connector

Memorystore

IAM

Gatekeeper

33 of 45

Demo:

Setting cloud guardrails with

OpenPolicyAgent

34 of 45

K8s workloads + Cloud workloads

GKE

Config

Connector

Memorystore

IAM

Cymbal

Shops

Gatekeeper

35 of 45

... Across multiple clouds...

GKE

Config

Connector

Memorystore

IAM

Cymbal

Shops

Gatekeeper

EKS

Cymbal

Ads

S3

Bucket

ACK

36 of 45

Are Config Connector and ACK enough?

Config Connector allows managing Google Cloud resources and ACK, enables same for Amazon Web Services resources

Still two very different tools to incorporate into the pipeline

Can we consolidate all this into one tool?

One ring popsicle to rule them all…

37 of 45

Crossplane

Open Source Kubernetes add-on; everything defined as KRM

Support for resource management on multiple platforms (GCP, AWS, Azure, Alibaba)

Assemble multiple resources into a composite unit and expose them as single resource definition

Set up policies and guardrails for cloud resources

38 of 45

How Crossplane Works

Extends the K8s API by introducing more CRDs with their own controller

A CRD per cloud provider to maintain access configuration

Enables compositions of cloud resources into higher level abstractions

39 of 45

Demo:

Unifying multicloud resource management with Crossplane

40 of 45

Demo!

Memorystore

IAM

GKE

Cymbal

Shops

EKS

Cymbal

Ads

S3

Bucket

Crossplane

41 of 45

Wrap-up!

There is are lots of ways to manage cloud infrastructure.

Kubernetes Resource Model (KRM) can act as the common data model to define all infrastructure in a declarative way

Different cloud providers have their own solutions to manage resources as a KRM entity

Efforts such as Crossplane enables a KRM based model with potential to abstract the underlying provider

42 of 45

Things we didn’t cover!

How does your KRM get from Git to your cluster(s)?

Transforming cloud KRM with kustomize / kpt.

RBAC and access control for cloud KRM.

Rego, the OPA Policy language

Other first-party tools, eg. Azure Service Operator

43 of 45

Resources

44 of 45

Try it out!

45 of 45

Thank You!