65
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Tiffany Jernigan @tiffanyfayj Developer Advocate, AWS Christoph Kassen @christoph_k Solutions Architect, AWS kubernetes on aws

kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Tiffany Jernigan @tiffanyfayj

Developer Advocate, AWS

Christoph Kassen @christoph_k

Solutions Architect, AWS

kubernetes on aws

Page 2: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Containers

Packaging

Distribution

Immutableinfrastructure

Page 3: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 4: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Open source containermanagement platform

Helps you runcontainers at scale

Gives you primitives for building

modern applications

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

What is kubernetes?

Page 5: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

SCALE PERFORMANCE BREADTH

A single extensible API

Page 6: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Vibrant and growing community

of users and contributors

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 7: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

ON-PREMISES CLOUD

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Kubernetes can be run anywhere!

Page 8: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Cloud-native applications

MICROSERVICE TOOLING NATIVE APPLICATIONS

Page 9: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

“Run Kubernetes for me.”

“Native AWS integrations”

“An open source Kubernetes

experience.”

Page 10: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

ELASTIC CONTAINER SERVICE FOR KUBERNETES

GA yesterday 6/5!

@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 11: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Amazon Container Services

Page 12: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

EKS is Kubernetes Certified

Page 13: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Open Source Kubernetes Community

Kuberneteshttps://github.com/kubernetes/kubernetes

CNI pluginhttps://github.com/aws/amazon-vpc-cni-k8s

Heptio AWS Authenticatorhttps://github.com/heptio/authenticator

Virtual Kubelethttps://github.com/virtual-kubelet/virtual-kubelet/

SIG AWS

https://github.com/kubernetes/community/tree/master/sig-aws

Cloud Provider Working Grouphttps://github.com/kubernetes/community/tree/master/wg-cloud-provider

External-DNShttps://github.com/kubernetes-incubator/external-dns

CoreOS ALB Ingresshttps://github.com/coreos/alb-ingress-controller

CODE REVIEWS

FIXING BUGS

IMPLEMENTING

NEW FEATURES

Page 14: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

EKS - Customers

C r e a t e E K S

c l u s t e r

P r o v i s i o n

w o r k e r n o d e s

L a u n c h a d d - o n s

L a u n c h

w o r k l o a d s

Page 15: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

EKS - Kubernetes Control Plane

C r e a t e

c l u s t e r

C r e a t e H A C o n t r o l

P l a n e

I A M i n t e g r a t i o n

C e r t i f i c a t e

M a n a g e m e n t

S e t u p L B

Page 16: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

mycluster.eks.amazonaws.com

AvailabilityZone 1

Availability Zone 2

Availability Zone 3

Kubectl

Workers

Page 17: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

EKS Architecture

@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 18: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

EC2 Worker Nodes

EKS Control Plane

Customer VPC EKS VPC

Network Load

Balancer

ENI

API Access

KubectlExec/Logs

TLS

Static IPs

Autoscaling Group

EKS Architecture

Page 19: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

IAM Authentication

Page 20: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Kubectl

3) Authorizes AWS Identity with RBAC

K8s API

1) Passes AWS Identity

2) Verifies AWS Identity

4) K8s actionallowed/denied

AWS Auth

IAM Authentication + kubectl

https://github.com/heptiolabs/kubernetes-aws-authenticator

Page 21: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

EKS Worker Nodes

Page 22: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

kubectl

AWS Auth

config map & RBAC

Workers

Role

Role

Worker provisioning

Page 23: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Metrics

Nodes

Node exporter

Pod/Container

Kube-state-metrics

cAdvisor

Application

/metrics

JMX

Cluster-wide Aggregator

Prometheus, Heapster

Visualizer

Grafana, Kibana, Dashboard

Data Model

InfluxDB, Graphite

Alerting

AlertManager, Kapacitor

Page 24: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Networking

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Page 25: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Native VPC networkingwith CNI plugin

Pods have the same VPC address inside the pod

as on the VPC

Simple, securenetworking

Open source andon Github

…{ }

https://github.com/aws/amazon-vpc-cni-k8s

Page 26: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Nginx Pod

Java Pod

ENI

Veth IP: 172.16.1.147

Veth IP: 172.16.1.224

Nginx Pod

Java Pod

ENI

Veth IP: 172.16.1.38

Veth IP: 172.16.1.24

ec2.associateaddress()

VPC Subnet – 172.16.1.0/24

Instance 1 Instance 2

Primary Private IP: 172.16.1.118

Secondary IPs:172.16.1.147, 172.16.1.224, …

Primary Private IP: 172.16.1.15

Secondary IPs:172.16.1.38, 172.16.1.24, …

172.16.0.0/16

Page 27: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

How do I configure network security with EKS?

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 28: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Kubernetes Network Policies enforce network

security rules

Calico is the leadingimplementation of the

network policy API

Open source, activedevelopment (>100

contributors)

Commercial supportavailable from Tigera

https://www.projectcalico.org/

Page 29: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

STAGE SEPARATION “TENANT” SEPARATIONFINE-GRAINED

FIREWALLSCOMPLIANCE

Namespaces – withoutnetwork policy, they are

not network isolated

Reduce attack surfacewithin microservice-based applications

Isolate dev, test, andprod

E.g., PCI, HIPAA

Page 30: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

What version of Kubernetes does EKS support?

1.10.3 currently

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 31: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Kubernetes Autoscaling with Amazon EKS

Page 32: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Auto Scaling

Two optionsAWS AutoScalingk8s Cluster Auto Scaler

Cluster AutoscalerReactive

Aware of Pod / Cluster state

Utilizes AWS AutoScaling

AWS AutoScaling

Scaling on CloudWatchMetrics

Cluster

Horizontal Pod AutoscalerScales pods in response tok8s generated metrics (CPU)

Pods

Page 33: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

❯ helm search mysql> helm search mysql

NAME CHART VERSION APP VERSIONDESCRIPTION

stable/mysql 0.6.0 5.7.14 Fast, reliable, sc

stable/prometheus-mysql-exporter 0.1.0 v0.10.0 A Helm chart for p

stable/percona 0.3.2 5.7.17 free, fully compat

...

❯ helm install install stable/mysql

[displays README + information about deployment]

❯ helm listNAME REVISION UPDATED STATUS CHART NAMESPACE

nobby-cow 1 Wed Jun 6 12:54:00 2018 DEPLOYED mysql-0.6.0 default

Package manager that allows you to bundle updeployment resources and publish them

https://github.com/kubernetes/helm

Page 34: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Hosting Helm repositories

• Anywhere that serves HTTP can host a helm repo

• Host private Helm Repo with Chartmuseum https://github.com/kubernetes-helm/chartmuseum

• There’s also a handy plugin for S3!

• This means IAM Role = auth for your repo ☺

• https://github.com/hypnoglow/helm-s3

Page 35: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Deploying Helm on EKS

Helm 2.9+ works with EKSRBAC permissions required

kubectl -n kube-system create serviceaccount tiller

kubectl create clusterrolebinding tiller --clusterrole cluster-admin --

serviceaccount=kube-system:tiller

helm init --service-account tiller

Page 36: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Demo

@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 37: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Know-how & Tools

@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 38: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Load Balancing

Page 39: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Nginx PodsEC2 instances

kube-proxy:32002

nginx-service:32001

Internet

10001:8080

10002:8080

10003:8080

Request to NGINX Pod {NLB}:443

NLB

NLB Forwards to the node {node:32001}

Service Type – LoadBalancer (NLB)

k8s service ClusterIPreceives request

kube-proxy load balances to pods

Page 40: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Network Load BalancerapiVersion: v1

kind: Service

metadata:

name: nginx

namespace: default

labels:

app: nginx

annotations:

service.beta.kubernetes.io/aws-load-balancer-type: "nlb"

spec:

type: LoadBalancer

externalTrafficPolicy: Local

ports:

- name: http

port: 80

protocol: TCP

targetPort: 80

selector:

app: nginx

More options:• Draining• Logging• SSL Certs• Tagging• Security groups• Health checks

https://github.com/kubernetes/kubernetes/blob/master/pkg/cloudprovider/providers/aws/aws.go

Page 41: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Nginx Pods

EC2 instances

kube-proxy:32001

nginx-service:32003

Internet

Request to NGINX Pod {ALB}:443

ALB

ALB Routes based on the path.

/api

/home

10002:8080

Webapp Pods

10002:8080

Installation: https://github.com/pahud/eks-alb-ingress

Ingress Type – CoreOS ALB Ingress

kube-proxy:32002

webapp-service:32004

Load Balances to pods

Proxies request to the k8s serviceClusterIP

Page 42: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

DNS

Page 43: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Automatic Route53 DNS creation for servicesapiVersion: v1

kind: Service

metadata:

name: nginx

annotations:

# Uses https://github.com/kubernetes-incubator/external-dns

external-dns.alpha.kubernetes.io/hostname: nginx.highlyavailable.systems.

spec:

type: LoadBalancer

ports:

- port: 80

name: http

targetPort: 80

selector:

app: nginx

Page 44: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Automatic Route53 DNS creation for IngressapiVersion: extensions/v1beta1

kind: Ingress

metadata:

name: nginx

annotations:

kubernetes.io/ingress.class: "nginx"

spec:

rules:

- host: nginx.highlyavailable.systems

http:

paths:

- backend:

serviceName: nginx

servicePort: 80

Page 45: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Scheduling

Page 46: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Controlling scheduling

Resource requirements

Resource filters

Page 47: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Limit resource usage

Container A Container B

limit

request

600m

600m

limit

request

800m

400m

⎲⎳ Pod CPU and memory resources

Page 48: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Resource Quotas

apiVersion: v1

kind: Pod

metadata:

name: production

spec:

containers:

- name: nginx-pod

image: nginx

resources:

limits:

memory: "800Mi"

cpu: "800m" # 0.8 vCPU

requests:

memory: "600Mi"

cpu: "400m“ # 0.4 vCPU

Applied per NamespaceapiVersion: v1kind: ResourceQuotametadata:

name: productionspec:

hard:requests.cpu: "1"requests.memory: 1Gilimits.cpu: "2"limits.memory: 2Gi

ResourceQuotadefined both, so Pod must define both

Pod Resource Request

Page 49: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Controlling scheduling

Resource requirements

Constraints• Taints Node-level• Tolerations Pod-level

Topology filters

Page 50: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Taints and Tolerations# Taint node

$ kubectl taint nodes ip-10-0-32-12.us-west-2.compute.internal \

skynet=false:NoSchedule

# Tolerations

kind: Podspec:

tolerations:- key: skynetoperator: Equalvalue: “false”effect: NoSchedule

[...]

Match taint to schedule onto tainted node

Page 51: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Controlling scheduling

Resource requirements

Constraints• Taints Node-level• Tolerations Pod-level

Affinity/Anti-AffinityTopology filters

Page 52: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Affinity / Anti-Affinity

● Control scheduling onto nodes○ Combine with Taints & Tolerations

● Distribute Pods across cluster

affinity:

nodeAffinity:

requiredDuringSchedulingIgnoredDuringExecution:

nodeSelectorTerms:

- matchExpressions:

- key: "beta.kubernetes.io/instance-type"

operator: In

values: [“r4.large",“r4.xlarge"]

Page 53: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Deployment Strategies

Page 54: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Rolling UpdateapiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: my-app

labels:

app: my-app

spec:

replicas: 10

strategy:

type: RollingUpdate

rollingUpdate:

maxSurge: 1 # Numeric or percentage based value

maxUnavailable: 0

[...]

Page 55: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Blue / Green Deployment

apiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: my-app-blue

labels:

app: my-app

spec:

replicas: 3

template:

metadata:

labels:

app: my-app

version: blue

[...]

BlueapiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: my-app-green

labels:

app: my-app

spec:

replicas: 3

template:

metadata:

labels:

app: my-app

version: green

[...]

Green

Page 56: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Blue / Green Deployment

Bluekind: Service

metadata:

name: my-app

labels:

app: my-app

spec:

type: LoadBalancer

ports:

- name: http

port: 80

targetPort: http

selector:

app: my-app

version: blue

kind: Service

metadata:

name: my-app

labels:

app: my-app

spec:

type: NodePort

ports:

- name: http

port: 80

targetPort: http

selector:

app: my-app

version: green

Green

kubectl patch service my-app -p '{"spec":{"selector":{"version":"green"}}}'

Page 57: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Canary Deployment

Production

apiVersion: extensions/v1beta1kind: Deploymentmetadata:

name: my-app-prodlabels:

app: my-appspec:

replicas: 9template:

metadata:labels:

app: my-appspec:

containers:- name: my-app

image: images/container:v1

[...]

apiVersion: extensions/v1beta1kind: Deploymentmetadata:

name: my-app-canarylabels:

app: my-appspec:

replicas: 1template:

metadata:labels:

app: my-appspec:

containers:- name: my-app

image: images/container:v2

[...]

More examples at https://container-solutions.com/kubernetes-deployment-strategies/

Canary

Page 58: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Network Policies

Page 59: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Network Policy

kind: NetworkPolicyapiVersion: networking.k8s.io/v1metadata:

name: web-allow-prodspec:

podSelector:matchLabels:

app: webingress:- from:- namespaceSelector:

matchLabels:purpose: production

Select affected Pods

Define traffic that is allowed

Page 60: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Want to learn more?

Page 61: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Tooling and Ecosystem

https://github.com/ramitsurana/awesome-kubernetes

https://discuss.kubernetes.io/

http://slack.k8s.io/

TGIK Playlist: https://www.youtube.com/playlist?list=PLvmPtYZtoXOENHJiAQc6HmV2jmuexKfrJ

Page 62: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

EKS – Getting started

https://aws.amazon.com/eks

https://aws.amazon.com/getting-started/projects/deploy-kubernetes-app-amazon-eks/

https://aws.amazon.com/blogs/aws/amazon-eks-now-generally-available/

https://aws.amazon.com/blogs/compute/https://aws.amazon.com/blogs/opensource/category/compute/amazon-elastic-container-service-for-kubernetes/

https://medium.com/containers-on-aws

Page 63: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Questions?

@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Page 64: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.@ C H R I S T O P H _ K @ T I F F A N Y F A Y J

Please complete the session survey in the

summit mobile app.

Page 65: kubernetes on aws - aws-de-media.s3.amazonaws.comaws-de-media.s3.amazonaws.com/images/AWS_Summit_2018/June6/BF... · © 2018, Amazon Web Services, Inc. or its affiliates. All rights

© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

https://aws.amazon.com/containers

@christoph_k

@tiffanyfayj

Special thanks to:Paul Maddox, Abby Fuller, Nishi Davidson, Brandon Chavis, Arun

Gupta, Chris Hein, Omar Lari, and many more...

Thank You

@ C H R I S T O P H _ K @ T I F F A N Y F A Y J