DeveloperPlayBook
Python
Python
  • Introduction
  • Architecture
    • Technology Stack
    • ADR Records
  • Design
  • Bootstraping
  • Development Environment
    • Accounts (AWS, GCP, CircleCI)
  • Services/API
    • Serverless
    • Containers
    • Python
    • Firebase
    • Chatbots
    • Testing
  • Frontend
    • Serverless
    • Containers
    • Chatbot
  • Plattform
  • IAM - IAMaaS
  • Persistance - DBaaS
    • Serverless
    • Container
  • Event Driven / Streaming aaS
    • Kinesis
  • AI - AIaaS
  • Production / Reliability Engineering
  • create-k8s-secrets
  • VI
  • Tools
Powered by GitBook
On this page
  • Platform & Infrastructure
  • Containers or serverless
  • Containers
  • Infrastructure Automation with - Terraform
  • Setup Docker Environment
  • Setup Kubernetes
  • Setup Service Mesh
  • Tutorial
  • Service Discovery
  • Register your DOMAIN
  • Encryption - how to use the public cloud securly? N26?

Plattform

PreviousChatbotNextIAM - IAMaaS

Last updated 7 years ago

Platform & Infrastructure

The platform provides the tools to increase productivity it should abstract away the operations tasks to get fast feedback loops but it also should design for change as we should be prepared that we have to change in the future:

  • Serverless (great speed and plattform) vs Istio (great portability) or Flask on Serverless for speed and platform but migratable?

  • SaaS Components for

    • Reliability aaS - Logging

    • ... but don't forget ports and adapters

Architecture Decisions

Containers or serverless

Serverless increases the efficiency of your implementation. But at the same time you bind yourself very tightly to a special vendor like Amazon with AWS Lambda. Another Option is to use a multi cloud apporach and use Containers as your abstraction layer - Lambdas also use containers themselves. Downside you don't have the you pay only what you use and you miss the non functional features the platform provides like monitoring, routing ... This is where service meshs like Istio come into play.

Can you integrate serverless with a service mesh and when to do it?

Containers

Infrastructure Automation with - Terraform

Setup Docker Environment

Create Dockerfile

docker build -t products:1.0.0 .

Setup Kubernetes

Local Development Environment

minikube start --memory 4096
#find the locally configure cluster where tiller will be installed by helm
kubectl config current-context

#install helm on client / ci/cd pipeline
brew install kubernetes-helm

#https://github.com/istio/istio/tree/master/install/kubernetes/helm/istio
git clone https://github.com/istio/istio.git
cd istio
kubectl create -f install/kubernetes/helm/helm-service-account.yaml

# for production secure helm https://docs.helm.sh/using_helm/#securing-your-helm-installation
helm init \ 
--tiller-tls \ 
--tiller-tls-verify \ 
--tiller-tls-ca-cert=ca.pem \ 
--tiller-tls-cert=cert.pem \ 
--tiller-tls-key=key.pem \ 
--service-account=tiller

helm install install/kubernetes/helm/istio --name istio

To build images directly in minishift use minikube's built-in docker daemon:

eval $(minikube docker-env)
docker ps
kubectl create secret generic gcloud-cred --from-file=/Users/den/.config/keys/marketplaceapp.json

Production Environment

In my experience maintaining and setting up a kuebrnetes cluster is hard - there are now many great fully manged offerings: Openshift, AWS EKS, IBM, Microsoft, Google GKE, Joyent Kubernetes

TODO

Setup Service Mesh

What is Istio?

  • Source:

    • Istio Introduction:

  • Improve development time (library vs sidecar)

  • improve plattform (tracing, a/b testing, dashboarding, service graph)

  • ... without changing the code!

Tutorial

Setup a kubernetes cluster (see chapter above) then install Istio:

curl -L https://git.io/getLatestIstio | sh -
export PATH="$PATH:/Users/den/repo/istio-0.5.0/bin"
cd istio-0.5.0
kubectl apply -f install/kubernetes/istio.yaml
kubectl apply -f install/kubernetes/istio-auth.yaml
kubectl apply \
  -f install/kubernetes/addons/prometheus.yaml \
  -f install/kubernetes/addons/grafana.yaml \
  -f install/kubernetes/addons/servicegraph.yaml \
  -f install/kubernetes/addons/zipkin.yaml

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /tmp/tls.key -out /tmp/tls.crt -subj "/CN=d10l.de"
kubectl create -n istio-system secret tls istio-ingress-certs --key /tmp/tls.key --cert /tmp/tls.crt

#get external ip
kubectl get svc -n istio-system
minikube ip
export GATEWAY_URL=$(kubectl get po -l istio=ingress -n istio-system -o 'jsonpath={.items[0].status.hostIP}'):$(kubectl get svc istio-ingress -n istio-system -o 'jsonpath={.spec.ports[0].nodePort}')
Deploy app
kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/kube/bookinfo.yaml)
kubectl get services

Deploy

kubectl apply -f <(istioctl kube-inject -f ./deployment.yaml)

Setup SDK locally and in Pipeline

Install Google Cloud SDK (MacOS)

brew cask install google-cloud-sdk
#Retrieve your credentials for kubectl (replace <cluster-name> with the name of the cluster you want to use, and <zone> with the zone where that cluster is located):
gcloud container clusters get-credentials <cluster-name> --zone <zone> --project <project-name>
Grant cluster admin permissions to the current user (admin permissions are required to create the necessary RBAC rules for Istio):
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$(gcloud config get-value core/account)
#download istio
curl -L https://git.io/getLatestIstio | sh -
# go to folder
cd istio-0.5.0
# add istiocrl
export PATH=$PWD/bin:$PATH
#Install Istio and enable mutual TLS authentication between sidecars.:
kubectl apply -f install/kubernetes/istio-auth.yaml
# Optional: If your cluster has Kubernetes version 1.9 or greater, and you wish to enable automatic proxy injection, install the sidecar injector webhook using the instructions at (/docs/setup/kubernetes/sidecar-injection.html#automatic-sidecar-injection).

#Verify
kubectl get svc -n istio-system
kubectl get pods -n istio-system

#create/update the namespace for my application with istio enabled
kubectl label namespace <namespace> istio-injection=enabled
# isnstall BookInfo Sample https://istio.io/docs/guides/bookinfo.html
kubectl create -n <namspace> -f <your-app-spec>.yaml

Access the non exposed components:

#login first
gcloud container clusters get-credentials marketplace-istio \
      --zone us-east1-b --project trusty-acre-156607

kubectl -n istio-system port-forward \
  $(kubectl -n istio-system get pod -l app=zipkin -o jsonpath='{.items[0].metadata.name}') \
  9411:9411 &

kubectl -n istio-system port-forward \
  $(kubectl -n istio-system get pod -l app=grafana -o jsonpath='{.items[0].metadata.name}') \
  3000:3000 &

kubectl -n istio-system port-forward \
  $(kubectl -n istio-system get pod -l app=servicegraph -o jsonpath='{.items[0].metadata.name}') \
  8088:8088 &

kubectl -n istio-system port-forward \
  $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') \
  9090:9090 &

kubectl proxy (8080/ui -> management ui)
---
###########################################################################
# Ingress resource (gateway)
##########################################################################
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  ...
spec:
  tls:
    - secretName: istio-ingress-certs # currently ignored
  rules:
  - ...

---

Find your static IP address:

kubectl get ingress -o wide
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
# minikube
kubectl apply -f <(istioctl kube-inject -f ./deployment.yaml --includeIPRanges=10.0.0.1/24)
#for gke check https://istio.io/docs/tasks/traffic-management/egress.html
gcloud container clusters describe marketplace-istio --zone=us-east1-b | grep -e clusterIpv4Cidr -e servicesIpv4Cidr
kubectl apply -f <(istioctl kube-inject -f ./deployment.yaml --includeIPRanges=10.12.0.0/14,10.15.240.0/20)

Save docker image in docker hub to use it in kubernetes cluster

docker login
docker tag products:1.2.0 dennisseidel/products:1.2.0
docker push dennisseidel/products:1.2.0

and add it to the deloyment config

create the secret with

kubectl create secret generic gcloud-cred --from-file=/Users/den/.config/keys/marketplaceapp.json

Service Discovery

Register your DOMAIN

Encryption - how to use the public cloud securly? N26?

Other Serverless Assets:

Containers on AWS:

Build the dockerfile ().

When you want to bring your docker containers into production - you need to orchestrate those containers. This is where helps getting a reliable and reporducable, production read ( scalable ...), "simple" (routes, services, ...), vendor independent (compared to serverless) and multi cloud ready solution.

Start minikube []

Setup and tiller [] and Istio [] / helm install currently not working check back in a few weeks.

Create Env variables:

Create secrets:

(Udemy Course Istio)

Set it up (you should do this with in Mind (Automation is everything!):

?

Register with

Install Istio:

To enable TLS create certficate and deploy it as a secret and add the following to the ingress config (

Add your own domain to the static ip address of the cluster:

Setup your DNS (with Route53)

Remove untagged images and stopped containers

Small images

testing with postman and different environments:

Egress Rules currently don't work well with HTTPS so better enable direct connection:

Mount Containers locally:

Use Envoy on ECS:

File based Maleware detection :

Persistance - DBaaS (DynamoDB)
IAM - IAMaaS
Event Driven / Streaming aaS
AI - AIaaS
Select Application Runtime: Serverless over Istio for now
https://serverless.com/blog/serverless-faas-vs-containers/
http://rancher.com/containers-vs-serverless-computing/
https://medium.com/@jeffzzq/how-to-integrate-an-aws-lambda-function-into-your-kubernetes-service-mesh-5d665f351675
https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/
https://github.com/wardviaene/terraform-course
https://aws.amazon.com/blogs/apn/terraform-beyond-the-basics-with-aws/
https://github.com/shuaibiyy/awesome-terraform
https://github.com/mcuadros/terraform-provider-helm
https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html
https://www.terraform.io/intro/getting-started/install.html
Python Connexion Docker Tutorial
Install Docker
tagging
Kubernetes
https://de.slideshare.net/InfoQ/building-a-microservices-platform-with-kubernetes
Source
Helm
Source
Source
https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
https://kubernetes.io/docs/concepts/configuration/secret/
https://programmaticponderings.com/2017/12/22/deploying-and-configuring-istio-on-google-kubernetes-engine-gke/
https://www.youtube.com/watch?v=muoCgHkkPx
https://istio.io/docs/concepts/what-is-istio/overview.html
DevSecOps
https://www.joyent.com/blog/kubernetes-the-easy-way
https://www.terraform.io/docs/providers/kubernetes/guides/getting-started.html
Google Cloud Platform
https://cloud.google.com/sdk/docs/quickstart-macos
https://istio.io/docs/setup/kubernetes/quick-start.html
https://istio.io/docs/tasks/traffic-management/ingress.html\
https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip
https://serverless-stack.com/chapters/setup-your-domain-with-cloudfront.html
http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html
https://nickjanetakis.com/blog/alpine-based-docker-images-make-a-difference-in-real-world-apps
https://www.getpostman.com/docs/postman/environments_and_globals/variables
https://istio.io/blog/2018/egress-https.html
https://istio.io/docs/tasks/traffic-management/egress.html
https://docs.docker.com/storage/bind-mounts/#start-a-container-with-a-bind-mount
https://blog.turbinelabs.io/replacing-aws-application-load-balancers-with-envoy-2a25c74bde9a
https://console.aws.amazon.com/route53
https://medium.com/airbnb-engineering/binaryalert-real-time-serverless-malware-detection-ca44370c1b90
https://docs.aws.amazon.com/de_de/AmazonECS/latest/developerguide/ECS_CLI_tutorial.html
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cmd-ecs-cli-compose.html
https://blog.valiantys.com/en/expert-tips/deploying-docker-containers-aws