Kubernetes & the 12 factors
cloud applications
Ana Maria Mihalceanu
#JBCNConf2019
@ammbra1508#JBCNConf2019
HELLO!
I am Ana
Technical Lead @ IBM
Co-founder of Bucharest Software Craftsmanship Community
Why 12 factors & Kubernetes?
@ammbra1508#JBCNConf2019
PortabilityLocal vs
production
Run at push
of a button
Evolution
Declarative
formats
Scale up
with
minimal
changes
Clean
Contract
Continuous
deployment
Scenario
@ammbra1508#JBCNConf2019
FACTOR 1 - CODEBASE
@ammbra1508#JBCNConf2019
One codebase tracked in
revision control,
with multiple deployments.
FACTOR 1 - CODEBASE
@ammbra1508#JBCNConf2019
FACTOR 2 - DEPENDENCIES
@ammbra1508#JBCNConf2019
Explicitly declare and
isolate dependencies.
FACTOR 3 - CONFIGURATION
@ammbra1508#JBCNConf2019
FACTOR 3 - CONFIGURATION
@ammbra1508#JBCNConf2019
Store configuration in the environment.
kubectl create secret docker-registry ${SECRET_NAME}
--namespace ${CLUSTER_NAMESPACE}
--docker-server=${REGISTRY}
--docker-password=${TOKEN}
--docker-username=iamapikey --docker-email=a@b.com
FACTOR 4 – BACKING SERVICE
@ammbra1508#JBCNConf2019
FACTOR 4 – BACKING SERVICE
@ammbra1508#JBCNConf2019
Treat backing services as attached resources.
apiVersion: v1
kind: Secret
metadata:
name: cloudant
type: Opaque
data:
binding: {}
FACTOR 5 – BUILD, RELEASE, RUN
@ammbra1508#JBCNConf2019
FACTOR 5 – BUILD, RELEASE, RUN
@ammbra1508#JBCNConf2019
Strictly separate build
and run stages.
FACTOR 5 – BUILD, RELEASE, RUN
@ammbra1508#JBCNConf2019
FACTOR 6 – PROCESSES
@ammbra1508#JBCNConf2019
Execute the app as one or
more stateless processes.
Container
Filesystem
Persistent
Volume
Volume
FACTOR 6 – PROCESSES
@ammbra1508#JBCNConf2019
kubectl apply –f ${CREATE_VOLUME}.yaml
kubectl apply –f ${COPY_SCRIPTS_POLLER}.yaml
kubectl cp ./scripts ${POD}:/${LOCATION}
kubectl apply –f ${USE_SCRIPTS}.yaml
FACTOR 7 – PORT BINDING
@ammbra1508#JBCNConf2019
kubectl apply –f ${DEPLOYMENT_FILE}
FACTOR 7 – PORT BINDING
@ammbra1508#JBCNConf2019
Export services via port binding.
kubectl expose deployment/${NAME}
--type=”${SERVICE_TYPE}”
--name=${SERVICE_NAME}
FACTOR 8 – CONCURRENCY
@ammbra1508#JBCNConf2019
YAML
Deployment Replica Set
Selector Selector
Pod Template Template
replicas = 2 spec.replicas = 2
POD
POD
APPLY
FACTOR 8 – CONCURRENCY
@ammbra1508#JBCNConf2019
Scale out via the process model.
kubectl autoscale deployment {$DEPLOYMENT}
--min=${MIN_PODS} --max=${MAX_PODS}
--cpu-percent=${CPU}
--namespace=${NAMESPACE}
FACTOR 9 – DISPOSABILITY
@ammbra1508#JBCNConf2019
helm upgrade ${RELEASE} ${CHART} --recreate-pods
Fast startup Graceful shutdown
FACTOR 9 – DISPOSABILITY
@ammbra1508#JBCNConf2019
Application boot time
Rolling update one after another
FACTOR 10 – DEV PROD PARITY
@ammbra1508#JBCNConf2019
Time People
Tools
FACTOR 10 – DEV PROD PARITY
@ammbra1508#JBCNConf2019
Keep development, staging and production
as similar as possible.
kubectl create namespace ${NAMESPACE}
FACTOR 11 – LOGS
@ammbra1508#JBCNConf2019
FACTOR 11 – LOGS
@ammbra1508#JBCNConf2019
kubectl create secret generic logdna-agent-key
--from-literal=logdna-agent-key=<ingestion_key>
kubectl create -f
https://repo.logdna.com/ibm/prod/logdna-agent-ds-
us-south.yaml
FACTOR 12 – ADMIN PROCESSES
@ammbra1508#JBCNConf2019
Run admin/management tasks as one-off processes.
kubectl create configmap ${CONFIG}
--from-file=scripts/ -o yaml
kubectl apply –f ${ONE_TIME_JOB_CONFIGURATION}
@ammbra1508#JBCNConf2019
@ammbra1508#JBCNConf2019
TAKEAWAYS
Decouple
Decouple
infrastructure
complexity from your
application code.
Managed Services
Prefer managed
services in matters
involving
persistency.
Environment Parity
Keep your
environments as
similar as possible.
@ammbra1508#JBCNConf2019
@ammbra1508#JBCNConf2019
TAKEAWAYS
Stateless
Design your
application as
stateless.
Scale
Your application
should be able to
process diverse
workloads.
Monitor
Use appropriate
logging in application
code and implement
cluster-level logging.
@ammbra1508#JBCNConf2019
The strongest factor for success is self-esteem.
Believing you can do it, believing you deserve it,
believing you will get it.
Anonymous
“ “
@ammbra1508#JBCNConf2019
THANKS!
Any questions?
Useful links
http://ibm.biz/javanewsletter
https://bit.ly/2HIE5dK
@ammbra1508#JBCNConf2019

Kubernetes and the 12 factor cloud apps

  • 1.
    Kubernetes & the12 factors cloud applications Ana Maria Mihalceanu #JBCNConf2019
  • 2.
    @ammbra1508#JBCNConf2019 HELLO! I am Ana TechnicalLead @ IBM Co-founder of Bucharest Software Craftsmanship Community
  • 3.
    Why 12 factors& Kubernetes? @ammbra1508#JBCNConf2019 PortabilityLocal vs production Run at push of a button Evolution Declarative formats Scale up with minimal changes Clean Contract Continuous deployment
  • 4.
  • 5.
    FACTOR 1 -CODEBASE @ammbra1508#JBCNConf2019 One codebase tracked in revision control, with multiple deployments.
  • 7.
    FACTOR 1 -CODEBASE @ammbra1508#JBCNConf2019
  • 8.
    FACTOR 2 -DEPENDENCIES @ammbra1508#JBCNConf2019 Explicitly declare and isolate dependencies.
  • 9.
    FACTOR 3 -CONFIGURATION @ammbra1508#JBCNConf2019
  • 10.
    FACTOR 3 -CONFIGURATION @ammbra1508#JBCNConf2019 Store configuration in the environment. kubectl create secret docker-registry ${SECRET_NAME} --namespace ${CLUSTER_NAMESPACE} --docker-server=${REGISTRY} --docker-password=${TOKEN} --docker-username=iamapikey --docker-email=a@b.com
  • 11.
    FACTOR 4 –BACKING SERVICE @ammbra1508#JBCNConf2019
  • 12.
    FACTOR 4 –BACKING SERVICE @ammbra1508#JBCNConf2019 Treat backing services as attached resources. apiVersion: v1 kind: Secret metadata: name: cloudant type: Opaque data: binding: {}
  • 13.
    FACTOR 5 –BUILD, RELEASE, RUN @ammbra1508#JBCNConf2019
  • 14.
    FACTOR 5 –BUILD, RELEASE, RUN @ammbra1508#JBCNConf2019 Strictly separate build and run stages.
  • 15.
    FACTOR 5 –BUILD, RELEASE, RUN @ammbra1508#JBCNConf2019
  • 17.
    FACTOR 6 –PROCESSES @ammbra1508#JBCNConf2019 Execute the app as one or more stateless processes. Container Filesystem Persistent Volume Volume
  • 18.
    FACTOR 6 –PROCESSES @ammbra1508#JBCNConf2019 kubectl apply –f ${CREATE_VOLUME}.yaml kubectl apply –f ${COPY_SCRIPTS_POLLER}.yaml kubectl cp ./scripts ${POD}:/${LOCATION} kubectl apply –f ${USE_SCRIPTS}.yaml
  • 19.
    FACTOR 7 –PORT BINDING @ammbra1508#JBCNConf2019 kubectl apply –f ${DEPLOYMENT_FILE}
  • 20.
    FACTOR 7 –PORT BINDING @ammbra1508#JBCNConf2019 Export services via port binding. kubectl expose deployment/${NAME} --type=”${SERVICE_TYPE}” --name=${SERVICE_NAME}
  • 21.
    FACTOR 8 –CONCURRENCY @ammbra1508#JBCNConf2019 YAML Deployment Replica Set Selector Selector Pod Template Template replicas = 2 spec.replicas = 2 POD POD APPLY
  • 22.
    FACTOR 8 –CONCURRENCY @ammbra1508#JBCNConf2019 Scale out via the process model. kubectl autoscale deployment {$DEPLOYMENT} --min=${MIN_PODS} --max=${MAX_PODS} --cpu-percent=${CPU} --namespace=${NAMESPACE}
  • 23.
    FACTOR 9 –DISPOSABILITY @ammbra1508#JBCNConf2019 helm upgrade ${RELEASE} ${CHART} --recreate-pods Fast startup Graceful shutdown
  • 24.
    FACTOR 9 –DISPOSABILITY @ammbra1508#JBCNConf2019 Application boot time Rolling update one after another
  • 26.
    FACTOR 10 –DEV PROD PARITY @ammbra1508#JBCNConf2019 Time People Tools
  • 27.
    FACTOR 10 –DEV PROD PARITY @ammbra1508#JBCNConf2019 Keep development, staging and production as similar as possible. kubectl create namespace ${NAMESPACE}
  • 28.
    FACTOR 11 –LOGS @ammbra1508#JBCNConf2019
  • 29.
    FACTOR 11 –LOGS @ammbra1508#JBCNConf2019 kubectl create secret generic logdna-agent-key --from-literal=logdna-agent-key=<ingestion_key> kubectl create -f https://repo.logdna.com/ibm/prod/logdna-agent-ds- us-south.yaml
  • 30.
    FACTOR 12 –ADMIN PROCESSES @ammbra1508#JBCNConf2019 Run admin/management tasks as one-off processes. kubectl create configmap ${CONFIG} --from-file=scripts/ -o yaml kubectl apply –f ${ONE_TIME_JOB_CONFIGURATION}
  • 31.
    @ammbra1508#JBCNConf2019 @ammbra1508#JBCNConf2019 TAKEAWAYS Decouple Decouple infrastructure complexity from your applicationcode. Managed Services Prefer managed services in matters involving persistency. Environment Parity Keep your environments as similar as possible.
  • 32.
    @ammbra1508#JBCNConf2019 @ammbra1508#JBCNConf2019 TAKEAWAYS Stateless Design your application as stateless. Scale Yourapplication should be able to process diverse workloads. Monitor Use appropriate logging in application code and implement cluster-level logging.
  • 33.
    @ammbra1508#JBCNConf2019 The strongest factorfor success is self-esteem. Believing you can do it, believing you deserve it, believing you will get it. Anonymous “ “
  • 34.
  • 35.