Requirements for developing an application in Kubernetes

Today I plan to tell you how to write applications and what are the requirements for your application to work well in Kubernetes. So that there is no headache with the application, so that you do not have to invent and build some kind of "crutches" around it - and everything worked the way Kubernetes itself intended.



This lecture is part of the Slurm Night School in Kubernetes . You can watch the open theoretical lectures of the Evening School on Youtube, grouped into a playlist . For those who are more comfortable with text, not video, we have prepared this article.



My name is Pavel Selivanov, at the moment I am the lead DevOps engineer at Mail.ru Cloud Solutions, we create "clouds", we do management kubernetis and so on. My tasks now just include helping in development, rolling out these clouds, rolling out the applications that we write and directly developing the tools that we provide for our users.





DevOps- , , , , . , , , DevOps, , , . . Kubernetes — , , , .



, Kubernetes 1.3, , 1.2 — . — , , Kubernetes . . , , .



, , , (TL;DR) – «too long; don’t read». .





, , , , , , - .



— «ctrl+c, ctrl+v», , DevOps, : «, Kubernetes, ».



. . , .



:



  • , -, ( ?), Kubernetes, , ;
  • Kubernetes, Kubernetes - ;
  • , , ;
  • , graceful shutdown;
  • ;
  • ;
  • , cloud-native . Cloudnativeness, .




— , Kubernetes . Kubernetes . , - . , . - /var/log.





, , - , — rsyslog , - , , , , , , , -. , , - , , ( ?) . , , - .



Kubernetes , , – , , , .



, Kubernetes, , - - , Stdout/Stderr, , . , , . , Stdout/Stderr, Kubernetes, . JSON .



, . , , kubectl logs «». , , — - .



, , , . , Kubernetes, , , .



- , -, , , - . , Kubernetes DaemonSet - – , , , . - , , - , - , , -. . , , Elasticsearch, , . , Kibana, , , .



, , , , , Kubernetes, – .



-, . , exec, . – , , . , , . , , , , , . , — . , .



– , – . , , . , , , , . , -, , , — , , . , , , , Kubernetes, – .



, – , , , , . , Kubernetes, DevOps. – Dev Ops, .



, , JSON . - , , - print - , - , - , ; JSON, JSON , .



JSON - , , , . , , , , , - nginx, , , , , . nginx instance , -. , , , nginx instance , . .



, , , . , - , , , , , , . , , , , -, . -, .





stack trace — . , – , . - Elasticsearch , - , stack trace – , - , . stack trace - , .



( Sentry), , stack trace. , -, , , . , , , , -, .





Kubernetes: Kubernetes . , , – . , – , , . , .



, , . : , .





— , — ENV (environment) , , . , , JAVA, Python, Go, Perl , database host, database user, database password, . . .



ENV . Kubernetes, ENV Deployment. , , ENV ( ..), , ENV Deployment , , database password . Kubernetes. . , . DevOps, : «, , . ».



, . , postgres database, database name, database -, dbn - , , , .



, , Deployment — . , — . , . , .



, – , . Config.pi – , . - , – , .



, , , , .yaml. , , , , .



, YAML, , , JSON, , YAML . . , - ini. , , , , - , ini .



, , , Kubernetes — . Kubernetes, ConfigMap. configmap - , configmap , . , , , , . - , .



configmap, , , , configmap, . .



, , — , , . . , , , git. , git, git, – . , , git .



Health check



– , Health check. , Health check – , . -, , , ( ) - URL, , /health.



URL, , «, , 200» «, , - 500». , http, -, - , , . , , http, . -, daemon - , , daemon status, «, , daemon , ».



? , , — , , . , , , , , . , , , , — « , ..., , ».



— - , . . . Kubernetes, , , , , , . - java- , , , , . , , .



, , , Kubernetes, , , , .





, , Readiness/Liveness Kubernetes, , readiness - . readiness , , . readiness , , instance, , , . , Liveness Kubernetes , , «», «». liveness , Kubernetes, , .



, , , - readiness , liveness . readiness, liveness , Kubernetes , , – . . – , . , -, - , , , - . , . , , REST API . , , «200, , », , «200, , » — . .



, , /health, , «200, », , , , , - , , , . , «200, ». , , , .



, , Readiness/Liveness — readiness , liveness . , , , instance instance , . readiness , , , , «» , .



liveness , , , Kubernetes , liveness- . , . , , . , JS Mongo. - , Kubernetes, readiness, liveness , Kubernetes — . , - Mongo «» . , «».



, «», , , . «» — , — - , , - , - , . , , instance. , , , , , , , , . , , . , . – , instance , instances.



liveness , , . , «». , , , , . , , , , – , .



, readiness liveness , , , , , , . readiness . liveness , , , , liveness , .



liveness «». - — . — .



, , , . . , , , — , , «200». , . « -».



— . , «, » . .



- , - , - . , -.



, . , . , , : 204, 5, 10, 15, . , « ». , . , , , . , 502 – , - .



, . , , , — . , , « » — , . , . . , , , - , - , , — . .



, , . , , REST API, , , .



, , - , , , — , , - .



.



, Kubernetes , , - DevOps , Kubernetes. , (graceful) Kubernetes. Kubernetes , Kubernetes .



Graceful Shutdown



, Graceful Shutdown . , - , app stop — , , , - . , , SIGTERM «SIGTERM, , , ». .





, SIGTERM « , , , , , SIGTERM, ». .



? , . – - , , SIGTERM.



SIGTERM – , , , , , , , , , .



Kubernetes, . , Kubernetes, «, , » , , Kubernetes — Kubernetes - SIGTERM, - , , , , , Graceful ShutdownTimeout. , .



, , SIGTERM , - , «» — SIGKILL, , . , , - , . , , , 30 . , SIGTERM, , SIGTERM 30 . , , 45 , SIGTERM. 45 . , . , , , , — . 45 , , .



, , 2 . -, , , , - , SIGTERM, . . . , , , , - , - , -. , , , — , , . , , SIGTERM . , SIGTERM. , . , . , - websocket, , , , , . , .



, - exit-. , , , - exit- 1,5,255 . , , Linux , , . , . , -, , 0 . - , 0 . .



. , , . , . , . , , , . , , . — , — . websocket`, , .



- , , , websocket . - , , reload. , . : «, , !». : « ? ?». : «, , ». , . . , , websocket, . .





, . . , .



, , - , , Kubernetes . , … - : « ». , , , . , - . : «- , ». : « ?». , Kubernetes, , , . , : « , . ». . . , , .



? Kubernetes 2 . , – . , . , Kubernetes.



. , , 1 , 1 . , , oom killer, out of memory , — . CPU . CPU, , , , CPU . . – .



. – , Kubernetes , Kubernetes . – commit . , : « , CPU ». . node, , , 8 CPU. , 1 CPU, 7 CPU. , , 8 , 1 — , Kubernetes, CPU . CPU , Kubernetes , , , CPU.



, , Kubernetes ? , . , Kubernetes , , . , , . - . , . , . , , . , , (). , , , . . , , . , .



, , , Kubernetes. Kubernetes , , . . . , .





. , persistence Kubernetes?



, , , Kubernetes . , , : « Kubernetes ?». -, , , , , Kubernetes , .



. , , , , , cloud native . , , . , , , . . .



, , - , , - , , , ? Kubernetes ?



, , , Kubernetes stateless . , . .



, , , . ? – - S3, , , - . — S3. , « , , S3 ». , : « S3 ». .



- , , , , - , S3 , . - - , Kubernetes. Ceph - , , . Ceph, , . , , - Ceph, . , , Ceph , . Ceph , .



Ceph, .



- NFS . Kubernetes , NFS — . , , , , NFS - , , , , , . , - .



, , , - . , , , - , - , . . , , . , . , , - , -, , - . , , . . Kubernetes . , instance . , . . Kubernetes , , instances. Kubernetes . , , , . . instance - . , , , . , , , , . , , , .



, Kubernetes , volume. , volume empty dir. Kubernetes , , . , . . , , . Kubernetes empty dirs . , empty dir, . , empty dir . — . - , , . , , empty dir, , empty dir .



empty dir? , . , - , . , , , -, , , . Empty dir Kubernetes . , — . empty dir , , , , . - . , , , . Kubernetes.



Minio ? Minio – , , , - , - , . , Ceph. Minio - . HTTP . , S3. . , , buckets , , , – , , .



Empty dir ? . , , , . empty dir , . . , , kubernetes, , , empty dir. , , - , - , - empty dir .



Cloudnativeness



, Cloudnative. . Cloudnativeness .



, , . , , Cloudnative . , , , , . , , .





Kubernetes. Kubernetes. , , -. Kubernetes . - , . Kubernetes . ? , , , - Kubernetes, .



, . , , . - , Kubernetes — Kubernetes . - , , , - . , , . , Kubernetes. Kubernetes , - . - , , . Kubernetes , .



, Kubernetes. - Kubernetes — , - . , , , , , . , . , , . , . , -, , , . , Kubernetes .



. Kubernetes . , , , — Kubernetes . , . , Kubernetes , , . . . , , , , .



, , . Cloudnative . , . 9 , , , Cloudnative, , , , , , . 8 6 , Kubernetes , . 30 . , , .



, 30 - , Kubernetes, . . , , , , , .



, . , , Cloudnative, - , Infrastructure as a Code. , , , , . , , , git, CI\CD .



, , -, , . -, , . -, , , . -, . , , , : «, , , , ». . - , Cloudnative Infrastructure as a Code, , , , , . .



Kubernetes: , , . . , Kubernetes, 1-2 .




All Articles