Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elastic Scaling of (Micro)services with Kubernetes

Elastic Scaling of (Micro)services with Kubernetes

Splitting an application up into multiple independent services can be a good way to keep it scaling and ensure stability and developer productivity in larger, growing teams. But just splitting the codebase, creating APIs and deploying the code on some servers is not enough, somehow your services need to know where and how other services are accessible. Classical approaches like hardcoding everything in every service or having a central load-balancer can quickly lead to problems in terms of scalability and maintainability. In this talk I’ll show how we at ResearchGate tackled this challenge. With the help of tools like Consul, linkerd and Kubernetes we created a setup that allows us to quickly boot and shutdown services. This ensures that all servers are utilised optimally and load spikes can be reacted upon quickly and automatically.

Bastian Hofmann

May 17, 2017
Tweet

More Decks by Bastian Hofmann

Other Decks in Programming

Transcript

  1. $config = [ 'serviceA' => [ '192.168.0.1:8001', '192.168.0.2:8001', ], 'serviceB'

    => [ '192.168.0.1:8002', ], 'serviceC' => [ '192.168.0.2:8003', ] ];
  2. $config = [ 'serviceA' => [ '192.168.0.1:8001', '192.168.0.2:8001', ], 'serviceB'

    => [ '192.168.0.1:8002', ], 'serviceC' => [ '192.168.0.2:8003', ] ];
  3. Image • A docker image built from a Dockerfile that

    contains everything a service needs to run
  4. • A container runs a docker image. • Only 1

    process can run inside of a container Container
  5. Pod • A group of 1 or more containers •

    Same port space • Ports are not accessible from outside of the pod
  6. Volumes • Volumes can be mounted into a container to

    access a ConfigMap, Secret or a folder on the host
  7. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application

    POD ReplicaSet: 2 instances PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application POD
  8. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER ReplicaSet: 2

    instances PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER CONFIG WEB :80 PHP Application POD PHP Application POD
  9. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER ReplicaSet: 2

    instances PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER CONFIG WEB :80 https://php-app.k8s.foo.com:443/ PHP Application POD PHP Application POD
  10. FROM node:7 WORKDIR /opt/appmiral ADD . /opt/appmiral RUN apt-get install

    -y curl git && \ npm install bower@latest -g && npm install grunt@latest -g && \ npm install && bower install --allow- root && grunt build EXPOSE 9012 CMD node /opt/appmiral/dist/server.js
  11. ApiVersion: extensions/v1beta1 kind: Deployment metadata: name: appmiral spec: replicas: 2

    template: spec: containers: - name: appmiral image: your-registry/yourcompany/appmiral resources: requests: cpu: 1 memory: 200Mi env: - name: NODE_ENV value: "production" ports: - containerPort: 9012 livenessProbe: httpGet: path: /health port: 9012
  12. - name: appmiral image: your-registry/researchgate/appmiral resources: requests: cpu: 1 memory:

    200Mi env: - name: NODE_ENV value: "production" ports: - containerPort: 9012 livenessProbe: httpGet: path: /health port: 9012
  13. kind: Service apiVersion: v1 metadata: name: appmiral spec: ports: -

    name: http port: 9012 targetPort: 9012 protocol: TCP selector: app: appmiral
  14. apiVersion: extensions/v1beta1 kind: Ingress metadata: name: appmiral-ing spec: rules: -

    host: appmiral.kluster-01.rgoffice.net http: paths: - path: / backend: serviceName: appmiral servicePort: 9012
  15. DNS