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

Self-Healing Applications with Kubernetes

Self-Healing Applications with Kubernetes

My talk on building scalable, reliable, fault-tolerant, and self-healing applications using Kubernetes at DevFest Lahore 2019.

No matter what your language or framework of choice is, using strategies in this talk can help your application figure out if it's failing using custom-defined health checks that can automatically restart your app and try to bring it back to its last good state.

Video and more info: https://shyr.io/t/k8s-self-healing

Sheharyar Naseer

November 23, 2019
Tweet

More Decks by Sheharyar Naseer

Other Decks in Technology

Transcript

  1. Self-Healing Applications
    with Kubernetes

    View full-size slide

  2. @sheharyarn ! " #
    Sheharyar Naseer

    View full-size slide

  3. Why do I care?
    • DevOps is hard

    • From 1 instance on your laptop to 100s in production

    • Something breaks

    • Requires monitoring and manual intervention

    • SSH'ing into production at 3am on a Saturday night

    View full-size slide

  4. Holy Grail of DevOps
    • Imagine: Your server constantly monitoring for issues

    • And automatically Hxing them

    • You no longer hate your job and yourself

    • And you can Hnally have a life (Maybe?)

    View full-size slide

  5. Kubernetes
    • Container automation framework

    • Open-sourced by Google in 2014

    • Monitors, Detects and RectiHes issues in your cluster

    • Declarative, not Imperative

    View full-size slide

  6. Imperative System
    • Give your system explicit instructions

    • It executes them to get to your desired state

    • You still need to monitor for changes

    • Give more instructions in case something goes
    down

    View full-size slide

  7. Declarative System
    • Desired State

    • Tell Kubernetes what you want,

    not what to do

    • If stuX breaks

    • Kubernetes will automatically Hx it

    • Will always go back to desired state

    View full-size slide

  8. Architecture
    • Containers

    • Pods

    • Deployment

    • Services, Volumes, ReplicaSets, etc.

    View full-size slide

  9. Container
    FROM openjdk:8-jdk-alpine
    VOLUME /tmp
    RUN mkdir /k8s-demo
    COPY . /k8s-demo
    WORKDIR /k8s-demo
    RUN /k8s-demo/gradlew build
    RUN mv /k8s-demo/build/libs/*.jar /app.jar
    ENTRYPOINT ["java","-jar","/app.jar"]
    Architecture
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: app-deploy
    spec:
    replicas: 3
    ...
    template:
    spec:
    containers:
    - name: nginx
    image: nginx:1.7.9
    ports:
    - containerPort: 80
    - name: k8s-demo
    resources:
    limits:
    cpu: 6000m
    memory: 24Gi
    requests:
    cpu: 2000m
    memory: 10Gi
    Deployment

    View full-size slide

  10. Application Health
    • Pod Phases

    • Pending, Running, Succeeded, Failed, etc.

    • Health Checks

    • Readiness:

    Finished initializing and ready to accept requests

    • Liveness:

    Can process and respond to requests


    View full-size slide

  11. Application Health
    • Probes

    • Exec:

    Execute a command in the container

    • HTTP GET:

    Make a web request to check if a success response is returned

    • TCP Socket:

    Pe?orm a TCP check for an open poA

    View full-size slide

  12. Readiness
    readinessProbe:
    httpGet:
    path: /ready
    port: http
    initialDelaySeconds: 5
    timeoutSeconds: 1
    periodSeconds: 5
    failureThreshold: 3
    Self-Healing
    livenessProbe:
    httpGet:
    path: /healthy
    port: http
    initialDelaySeconds: 10
    timeoutSeconds: 10
    failureThreshold: 3
    Liveness

    View full-size slide

  13. Outro
    Previous talk (Deployment with K8S):

    to.shyr.io/io19-k8s



    Find these slides at:

    to.shyr.io/k8s-self-healing
    !
    !
    #
    shyr.io
    [email protected]
    sheharyarn

    View full-size slide