K8s - let's deploy an application

by Kamil Gałuszka

Kubernetes

Pods

  • Spin up a container (or multiple containers)
  • Governs IP/networking
  • Ephermal
  • Normally You don't deploy them directly
  • In other word, Pod is a single instance of an application

ReplicaSet and Deployment

  • A ReplicaSet ensures that a specified number of pod replicas are running at any given time
  • A Deployment controller provides declarative updates for Pods and ReplicaSets.​
  • ReplicaSets are managing scaling of pods. 
  • Pods are born & killed by ReplicaSets. They are never resurrected
kind: Deployment
apiVersion: apps/v1beta1
metadata:
  name: orchestrator
  labels:
    name: orchestrator-ruby
    role: orchestrator
spec:
  replicas: 2
  selector:
    matchLabels:
      name: orchestrator-ruby
      role: orchestrator
  strategy:
    rollingUpdate:
      maxUnavailable: 10%
      maxSurge: 10%
    type: RollingUpdate
  template:
    metadata:
      name: orchestrator-ruby
      labels:
        name: orchestrator-ruby
        role: orchestrator
    spec:
      containers:
      -
        name: orchestrator-ruby
        resources:
          requests:
            cpu: 40m
            memory: 50Mi
        image: orchestrator-ruby:latest
        imagePullPolicy: Never
        readinessProbe:
          httpGet:
            path: /healthcheck
            port: 80
          initialDelaySeconds: 15
          failureThreshold: 2
        livenessProbe:
          httpGet:
            path: /healthcheck
            port: 80
          failureThreshold: 2
          initialDelaySeconds: 15
        envFrom:
        -
          configMapRef:
            name: orchestrator-configmap
        ports:
        -
          name: a-http
          containerPort: 80

Service

  • Service are grouping pods
  • Grouping of pods is done by label selector
  • Service is routing requests/connections to specific pods
kind: Service
apiVersion: v1
metadata:
  name: orchestrator-ruby
  labels:
    name: orchestrator-ruby
    role: orchestrator
spec:
  ports:
  -
    name: http
    port: 80
    targetPort: a-http
    protocol: TCP
  selector:
    name: orchestrator-ruby
    role: orchestrator

ConfigMaps and Secrets

  • Any non-sensitive ENV variables you can store them in ConfigMap
  • All sensitive ENV variables should be store in secrets (encoded Base64)
apiVersion: v1
kind: ConfigMap
metadata:
  name: api-configmap
  namespace: staging
data:
  REDIS_URL: redis://redis-staging-master/

Helm

Package manager for k8s

  • Helm uses charts to deploy into cluster
  • A lot of different charts are available for example
    1. Redis
    2. PostgreSQL
    3. Elasticsearch etc.
  • Don't use it in production

Let's build an app

That is ...

...build from 3 microservices

  • Ruby Orchestrator
  • Python API 
  • NodeJS Worker

APIs

Ruby (Sinatra)

GET /healthcheck
GET /am-i-famous?name=<person_name>
GET /result/<job_id>
DELETE /result/<job_id>


Python (Flask)

GET /healthcheck
POST /job/
GET /result/<job_id>
DELETE /result/<job_id>

Used tools

  • Sinatra (Orchestrator)
  • Flask (API)
  • Commander (Worker)

Github Link:

Any Questions? 

Thanks!

We are hiring!

K8s - let's deploy an application

By Kamil Gałuszka

K8s - let's deploy an application

  • 192
Loading comments...

More from Kamil Gałuszka