How virtual but real architecture can help save your time and money

Krystian Różycki

Route Map

Route map

You are here

time ~30min

IaaS market share

Kubernetes

 Lambda

 Cost Optimization

Leader

When people say that they don’t have time for the architecture it literally means that they don’t know what they are doing

IaaS market share

Main Cloud Infrastructure as a Service (IaaS) providers - worldwide

  • Amazon (AWS)
  • Microsoft (Azure)
  • Google (Google Cloud Platform)
  • Alibaba (Alibaba Cloud)
  • Oracle (Oracle Cloud)
  • IBM (IBM Cloud)

Gartner IaaS Magic Quadrant 2012

Gartner IaaS Magic Quadrant 2013

Gartner IaaS Magic Quadrant 2014

Gartner IaaS Magic Quadrant 2015

Gartner IaaS Magic Quadrant 2016

Gartner IaaS Magic Quadrant 2017

Gartner IaaS Magic Quadrant 2018

Why AWS still dominates the cloud market

  • According to a MarketWatch, “AWS has cut prices more than 50 times since its launch in 2006″
  • New infrastructure and innovations (since 2006 has progressed into a platform for databases, developer apps, tools, and analytics)
  • Has more than 1 million users including big name companies such as Netflix and Airbnb
  • Vast solutions for different needs all under one umbrella
  • Fast and easily scalable solutions

AWS Global Infrastructure

AWS Global Infrastructure

What is k8s?

  • Kubernetes (k8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
  • Announced in mid-2014,  version 1.0 released on July 21, 2015
  • Developed by Google
  • On March 6, 2018, Kubernetes Project reached ninth place in commits at GitHub, and second place in authors and issues to the Linux kernel
  • Witten in GO Lang
  • Not only Docker

+

DEMO

>kubectl get nodes
>kubectl get nodes -o wide

Nodes

>kubectl get pods
>kubectl get pods -o wide

Pods


>kubectl scale --replicas 8 deployment frontend

Scale Up/Down

>kubectl set image deployment/frontend php-redis=rakieta/gb-frontend:v2
>kubectl rollout status deployment/frontend
>kubectl rollout undo deployment/frontend

Deployment

>kubectl delete pod <pod-id>
>kubectl get pods

Self-healing - pods

>kubectl get nodes
>kubectl get pods -o wide

Self-healing - nodes

What we just saw?

  • Replication of pods and nodes (scalability)
  • Self-healing mechanism
  • Simple deployment example and how it works
  • Autoscale mechanism example:
    • Horizontal Pod Autoscaler (HPA) 
    • Cluster Autoscaler (CA)
  • Some tools and commands like:
    • eksctl 
    • kubectl
    • kube proxy
    • kubernetes-dashboard
    • merics-server

Amazon EKS Pricing

  • You pay $0.20 per hour for each Amazon EKS cluster that you create. You can use a single Amazon EKS cluster to run multiple applications by taking advantage of Kubernetes namespaces and IAM security policies.
  • You pay for AWS resources (e.g. EC2 instances or EBS volumes) you create to run your Kubernetes worker nodes. You only pay for what you use, as you use it; there are no minimum fees and no upfront commitments.

Cost Comparison

Direct Deployment (on-demand instances) $32,040 $50,882 $43,730
​Direct Deployment (70% reserved instances) $29,883 $37,974 $31,830
​Managed Kubernetes (EKS,GKE, AKS - on-demand instances) $30,874 $50,064 $42,048
Managed Kubernetes (EKS,GKE, AKS - 70% reserved instances) $28,718 $37,156 $30,148

100 Core, 400 GB Kubernetes cluster

of Kubernetes workloads run on AWS

- Cloud Native Computing Foundation

51%

And many, many more...

AWS Lambda in short 

 

  • Introduced in November 2014
  • It's a Serverless solution
  • Executes only when needed
  • Scales automatically (from a few requests/day to
    thousands/ second)
  • Zero administration (server and operating system maintenance, capacity provisioning, automatic scaling, code monitoring, logging) this is done for You out of the box.
  • Runs your code on a high-availability compute infrastructure 
  • Really easy to use 

How it works? - simplyfied

Your Event

Your Code

lambda.zip

stored on Your
S3 bucket

trigger

copy

RUN

FORGET

UNPACK / PREPARE

AWS Infrastructure

API Gateway

15 available events to choose from and the number is still growing...

Every call/trigger does the same thing (scale)

Serverless framework...

https://serverless.com

...as a cool tool for developing/managing Your lambda

>sls create -t aws-python3 -p summit

Creating new lambda project

Code example

handler.py

Code example

serverless.yml

gives ability to store python requirements in requirements.txt or Pipfile

use docker to build requirements 

use API Gateway as lambda event trigger

Serverless: deployment

>sls deploy -v

AWS Lambda Pricing

  • You pay only for the compute time you consume - there is no charge when your code is not running
  • Free tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month.
  • For example:
    • bill for 2M/128MB/400ms = $2.07/MTH or $0.20/MTH

See more at: https://s3.amazonaws.com/lambda-tools/pricing-calculator.html

Requests 

Duration 

$0.20 per 1M

allocated memory / total time

Lambda vs EC2 - costs comparison

Setup and Configuration Lambda

Memory: 128 MB

Execution Limit: 30 sec

Permissions: Dynamo, S3 Access

Language: NodeJS

Setup and Configuration EC2

Instance Type: t2.micro

CPU: 1

Memory: 1GB

Language: NodeJS

A node server is created to listen on port 80.

Not only AWS

AWS Lambda Azure Functions GCP Functions Apache OpenWhisk
JavaScript(node.js) Yes Yes Yes Yes
Java Yes Yes No Yes (Partial)
C# Yes Yes No No
Python Yes Experimental No Yes
PHP No Experimental No Yes
Go Yes (Partial) No No No
F# No Yes No No
Swift No No No Yes

similar solution to lambda on different cloud providers

AWS Cost Optimization

Where is the leak...

I has been estimated that businesses waste average is around 30% of their cloud spend each year due to being charged for the services they do not use.

This is attributable to:

  • Overprovisioned and orphaned resources
  • Assigning resources to the wrong pricing structure
  • Leaving non-production resources running when they are not being used – typically those used for:
    • development
    • staging
    • testing.x

How to save some money while using cloud solutions?

  • Automate tear-down/creation of the non-production stacks (for example: dev stack to be available 7am-8pm) - it's easy to automate with lambda scheduled events
  • Checkout https://www.ec2instances.info for best prices of EC2 and RDS types according to Your needs (storage/memory/CPU/OS/...)
  • Checkout for more information and pricing programs on AWS (Save when you reserve, Pay less by using more)
  • Use Autoscaling Groups (to scale up/ down EC2 instances when needed)
  • Consider using Kubernetes (or similar) when serving app for big number of users - saves resources (autoscale), can reduce Your DevOps team (self-healing mechanizm, simple deployment, easy configuration, etc.)
  • Consider using Serverless (AWS Lambda or similar) - as a backend for webapp, automation tool, etc.

Thank You

presentation: stxsummit.krystianrozycki.com
code: github.com/riv2q/stxsummit_2019
contact: krystian.rozycki@stxnext.pl

Sources

  • https://aws.amazon.com/about-aws/global-infrastructure/
  • https://www.digitalocean.com/community/tutorials/an-introduction-to-kubernetes
  • https://docs.aws.amazon.com/cli/latest/
  • https://www.bmc.com/blogs/gartner-magic-quadrant-cloud-iaas/
  • https://www.51sec.org/2018/08/gartner-magic-quadrant-for-cloud-infrastructure-as-a-service-worldwide-2017-2016-2015-2014-2013-2012/
  • https://www.comparethecloud.net/articles/here-is-why-aws-still-dominates-the-cloud-market/
  • https://thenextweb.com/offers/2016/03/11/amazon-web-services-dominates-cloud-services-market/
  • https://stackshare.io/posts/companies-using-kubernetes-in-production-2018
  • https://aws.amazon.com/architecture/
  • https://serverguy.com/aws/aws-cost-optimization-case-study/
  • https://www.replex.io/blog/the-ultimate-kubernetes-cost-guide-aws-vs-gce-vs-azure-vs-digital-ocean
  • https://aws.amazon.com/eks/pricing/
  • https://www.cloudberrylab.com/resources/blog/aws-free-tier-ec2-lambda/
  • https://stratus10.com/5-ways-to-save-money-on-your-aws-bill/
  • http://www.theabcofcloud.com/lambda-vs-ec2-cost/
  • https://s3.amazonaws.com/lambda-tools/pricing-calculator.html
  • https://github.com/freach/kubernetes-security-best-practice/blob/master/README.md#firewall-ports-fire
  • https://docs.aws.amazon.com/eks/latest/userguide/sec-group-reqs.html
  • https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI
  • https://docs.aws.amazon.com/eks/latest/userguide/calico.html
  • https://github.com/weaveworks/eksctl
  • https://community.sdl.com/product-groups/sdl-tridion-dx/tridion-sites/tridion-developer/b/feed/posts/autoscaling-your-kubernetes-cluster-on-aws
  • https://eksctl.io
  • https://medium.com/uptime-99/kubernetes-hpa-autoscaling-with-custom-and-external-metrics-da7f41ff7846
  • https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-monitoring.html
  • https://caylent.com/kubernetes-autoscaling/
  • https://www.mirantis.com/blog/how-do-i-create-a-new-docker-image-for-my-application/
  • https://github.com/kubernetes/autoscaler
  • https://www.weave.works/blog/kubernetes-horizontal-pod-autoscaler-and-prometheus
  • https://medium.com/magalix/kubernetes-autoscaling-101-cluster-autoscaler-horizontal-pod-autoscaler-and-vertical-pod-2a441d9ad231
  • https://aws.amazon.com/lambda/features/
  • https://serverless.com/framework/docs/providers/aws/guide/quick-start/
  • https://www.serverlessconsultants.com/plugins/serverless-python-requirements/
  • https://github.com/serverless/examples