Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kubernetes: от юнги до капитана
Search
Igor Zibarev
November 03, 2018
Technology
18
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kubernetes: от юнги до капитана
Igor Zibarev
November 03, 2018
More Decks by Igor Zibarev
See All by Igor Zibarev
Философия Go
hypnoglow
0
120
Other Decks in Technology
See All in Technology
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
210
AIカンパニーへの転換を支えた、エンジニアの仕事の再定義
kworkdev
PRO
2
1.2k
大型犬好きによるPugの紹介
yamanoku
1
160
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
200
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
130
Active Record Connection Adaptersにおける長年の課題に再び取り組む
yahonda
0
150
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
4
1.4k
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
340
hackers_champloo_2026_tidb
makocchi
0
160
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
860
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
0
420
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
260
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
The browser strikes back
jonoalderson
0
1.8k
ラッコキーワード サービス紹介資料
rakko
1
5.3M
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
4 Signs Your Business is Dying
shpigford
187
23k
Being A Developer After 40
akosma
92
590k
Agile that works and the tools we love
rasmusluckow
331
22k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Transcript
Kubernetes: от юнги до капитана Игорь Зибарев
Адаптация приложения для Kubernetes Способы развертывания приложений Возможности платформы в
деталях 2
Цель 3
Контейнер 4
12factor.net 5
Config docker run \ -e SOME_SERVICE_ADDR="https: //some-service.company.tld" \ -e POSTGRES_DSN="postgres:
//
[email protected]
:5432/db" \ -e LOG_FORMAT="json" \ -e LOG_LEVEL="info" \ -e CACHE_DIR="/var/cache" \ -e API_PORT="8080" \ duck-service:v1.2.3 6
Один процесс FROM golang:1.10-alpine AS builder COPY . . RUN
go install FROM alpine:3.7 COPY --from=builder /go/bin/duck-service /usr/local/bin/duck-service USER 1000 ENTRYPOINT ["/usr/local/bin/duck-service"] 7
Одноразовый контейнер 8
Healthcheck 9
Graceful shutdown 10
var app DuckApp go func() { signals := make(chan os.Signal,
1) signal.Notify(signals, syscall.SIGTERM) <-signals log.Info("Shutting down ...") app.Shutdown() }() app.Run() 11
github.com/Yelp/dumb-init ENTRYPOINT ["/usr/bin/dumb-init", " --"] CMD ["bash", "-c", "do-some-pre-start-thing &&
exec my-app"] 12
Logs —Stdout / Stderr —Структурированные записи в JSON log.WithField(“s3.bucket", bucket).
WithField("s3.key", key). Info("Upload to S3") 13
Metrics — Формат Prometheus — Pull-модель router.Handle("/metrics", PrometheusMetrics()) 14
Cloud Native 15
Kubernetes как PaaS 16
Infrastructure (compute, net, …) Platform (ecosystem) Apps 17
С чего начиналось развертывание .kube ├── configmaps │ └── nginx.conf
├── deployments │ ├── app.yaml │ └── web.yaml ├── hpa │ ├── app.yaml │ └── web.yaml └── services ├── app.yaml └── web.yaml 18
apiVersion: apps/v1 kind: Deployment metadata: name: duck-backend spec: replicas: 2
selector: matchLabels: app: duck-backend template: metadata: labels: app: duck-backend spec: containers: - name: duck-backend image: registry.example.tld/duck/backend:v1.2.3 envFrom: - configMapRef: name: duck-backend ports: - containerPort: 8080 protocol: TCP 19
Дублирование для сред .kube ├── configmaps │ ├── nginx-dev.conf │
└── nginx.conf ├── deployments │ ├── app-dev.yaml │ ├── app.yaml │ ├── web-dev.yaml │ └── web.yaml ├── hpa │ ├── app.yaml │ └── web.yaml └── services ├── app.yaml └── web.yaml 20
— sed/replace — Terraform provider — Helm 21
22
values.yaml # Default values for the application. image: repository: registry.example.tld/duck/backend
tag: v1.2.3 pullPolicy: Always replicaCount: 3 resources: limits: cpu: 250m memory: 64Mi kafka: connString: "kafka.example.tld:9092" topic: "some-events" groupID: "app-consumers" 23
Кастомизация для среды # Values for minikube enviornment. replicaCount: 3
kafka: connString: "kafka.local:9092" config: logLeveL: debug 24
Новый сервис — helm create — Шаблон-ориентир — Интерактивная генерация
25
Chart Registry 26
Альтернатива: kustomize github.com/kubernetes-sigs/kustomize 27
Конфигурация Pod-а 28
Ресурсы apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "app.fullname"
. }} # ... # spec.template.spec.containers.* resources: requests: cpu: 250m memory: 40Mi limits: cpu: 400m memory: 64Mi 29
Diag endpoints func NewDiagRouter() *http.ServeMux { mux := http.NewServeMux() mux.Handle("/metrics",
prometheusMetrics()) mux.Handle("/healthz", healthCheckHandler()) mux.HandleFunc("/debug/pprof/", pprof.Index) // ... return mux } 30
Несколько портов apiVersion: apps/v1 kind: Deployment metadata: name: {{ template
"app.fullname" . }} # ... # spec.template.spec.containers.* ports: - containerPort: {{ .Values.apiPort }} protocol: TCP name: api - containerPort: {{ .Values.diagPort }} protocol: TCP name: diag 31
Пробы apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "app.fullname"
. }} # ... # spec.template.spec.containers.* livenessProbe: httpGet: path: /healthz port: diag periodSeconds: 5 timeoutSeconds: 2 32
Метрики apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "app.fullname"
. }} # ... # spec.template.annotations annotations: prometheus.io/scrape: "true" 33
Вместе с diag apiVersion: apps/v1 kind: Deployment # ... #
spec.template.annotations annotations: prometheus.io/scrape: "true" prometheus.io/port: "{{ .Values.diagPort }}" # ... # spec.template.spec.containers.* ports: - containerPort: {{ .Values.apiPort }} protocol: TCP name: api - containerPort: {{ .Values.diagPort }} protocol: TCP name: diag 34
Exporter apiVersion: apps/v1 kind: Deployment # ... # spec.template.annotations annotations:
prometheus.io/scrape: "true" prometheus.io/port: "metrics" # ... # spec.template.spec containers: - name: nginx image: nginx:1.14 # ... - name: prom-exporter image: sophos/nginx-vts-exporter:v0.9.0 ports: - name: metrics containerPort: 9913 35
Graceful shutdown Kubernetes выводит pod: —Pod status: ready ➡ terminating
—SIGTERM 36
37
Lifecycle Hooks blog.openshift.com/kubernetes-pods-life/ apiVersion: apps/v1 kind: Deployment # ... #
spec.template.spec containers: - name: app image: registry.example.tld/app:v1.2.3 # ... lifecycle: preStop: exec: command: ["sleep", "10"] 38
Эксплуатация платформы 39
Репликация apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "app.fullname"
. }} spec: replicas: {{ .Values.replicaCount }} # ... 40
Масштабирование apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: {{ template "app.fullname"
. }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: {{ template "app.fullname" . }} minReplicas: 5 maxReplicas: 20 targetCPUUtilizationPercentage: 70 41
Входящий трафик — Service Load Balancer — Ingress 42
Service Load Balancer apiVersion: v1 kind: Service metadata: name: {{
template "app.fullname" . }} spec: type: LoadBalancer ports: - name: http port: 80 targetPort: {{ .Values.apiPort }} selector: app: {{ template "app.name" . }} 43
Ingress apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ template "app.fullname"
. }} annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: app.public.tld http: paths: - path: / backend: serviceName: {{ template "app.fullname" . }} servicePort: http 44
Internal Load Balancer apiVersion: v1 kind: Service metadata: name: {{
template "app.fullname" . }} annotations: service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0 spec: type: LoadBalancer ports: - name: http port: 80 targetPort: {{ .Values.apiPort }} selector: app: {{ template "app.name" . }} 45
Internal Ingress apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ template
"app.fullname" . }} annotations: kubernetes.io/ingress.class: "nginx-internal" # <-- spec: rules: - host: app.private.tld http: paths: - path: / backend: serviceName: {{ template "app.fullname" . }} servicePort: http 46
github.com/kubernetes-incubator/external-dns 47
external-dns (SLB) apiVersion: v1 kind: Service metadata: name: {{ template
"app.fullname" . }} annotations: external-dns.alpha.kubernetes.io/hostname: app.public.tld # <-- spec: type: LoadBalancer ports: - name: http port: 80 targetPort: {{ .Values.apiPort }} selector: app: {{ template "app.name" . }} 48
external-dns (Ingress) apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ template
"app.fullname" . }} annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: app.public.tld # <-- http: paths: - path: / backend: serviceName: {{ template "app.fullname" . }} servicePort: http 49
TLS (SLB) apiVersion: v1 kind: Service metadata: name: {{ template
"app.fullname" . }} annotations: service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:123456 ..." service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443" spec: type: LoadBalancer ports: - name: https port: 443 targetPort: {{ .Values.apiPort }} # ... 50
github.com/jetstack/cert-manager 51
TLS (Ingress) apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ template
"app.fullname" . }} annotations: kubernetes.io/ingress.class: "nginx" kubernetes.io/tls-acme: "true" # <-- spec: rules: - host: app.public.tld # ... tls: - hosts: - app.public.tld secretName: {{ template "app.fullname" . }} 52
Распределение по нодам —Affinity —Taints —Tolerations 53
podAntiAffinity apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "app.fullname"
. }} # spec.template.spec affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - topologyKey: "kubernetes.io/hostname" labelSelector: matchLabels: app: {{ template "app.name" . }} release: {{ .Release.Name }} 54
tolerations apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "app.fullname"
. }} labels: app: {{ template "app.name" . }} # ... # spec.template.spec tolerations: - key: "node-class" operator: Equal value: "preemptible" effect: NoSchedule 55
PodDisruptionBudget apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: {{ template "app.fullname"
. }} labels: app: {{ template "app.name" . }} spec: selector: matchLabels: app: {{ template "app.name" . }} release: {{ .Release.Name }} maxUnavailable: 1 # <-- 56
И еще океан возможностей RBAC / Admission Webhooks / StatefulSet
/ Network Policies / CustomResourceDefinition / Security Policies / CronJob / Volumes / Aggregation / … 57
Утилиты для разработчиков 58
Minikube — Локальная разработка — Без внешних зависимостей Docker for
Mac github.com/kubernetes/minikube 59
Skaffold — Continuous Development — Build + Push + Deploy
— File watcher github.com/GoogleContainerTools/skaffold 60
Shell Переключение namespace и cluster github.com/ahmetb/kubectx github.com/jonmosco/kube-ps1 61
God Mode alias k=kubectl 62
Итог 63
64
Спасибо за внимание! 65 t.me/zibarev github.com/hypnoglow