Hari ini saya berencana untuk memberi tahu Anda cara menulis aplikasi dan apa saja persyaratan agar aplikasi Anda berfungsi dengan baik di Kubernetes. Sehingga tidak ada masalah dengan aplikasi ini, sehingga Anda tidak perlu menciptakan dan membuat semacam "kruk" di sekitarnya - dan semuanya berjalan sesuai keinginan Kubernetes.
Kuliah ini adalah bagian dari Slurm Night School di Kubernetes . Anda dapat menonton kuliah teori terbuka Sekolah Malam di Youtube, dikelompokkan ke dalam daftar putar . Untuk yang lebih nyaman dengan teks, bukan video, artikel ini sudah kami siapkan.
, DevOps Mail.ru Cloud Solutions, «», - . - , , , , .

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 , .
- 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 .