Kubernetes

Абстракциии
  • ResourceQuota
    • Установка ресурсов на NS
  • Probes
    • Liveness — При фаейле перезапуск пода
    • Start Up — При старте
    • Readnes — Исключение из балансировки с сервиса.
  • nodeSelector — Установка на конкретную ноду имеет только один лайбил без условий
  • Affinity
    • PodAntiafinity — Распределяет поды по на разные ноду
    • nodeAffinity — Распределение подов на определенные ноды с множеством условий
      • preferredDuringSchedulingIgnoredDuringExecution — Предпочитает ноду с необходимыми лейблами
      • requiredDuringSchedulingIgnoredDuringExecution — Выбирает только ноду с необходимыми параметрами если нету уходит в pending.
      • requiredDuringSchedulingIgnoredDuringExecution — Выбирает только ноду с необходимыми параметрами если нету уходит в pending, если кто то удаляет лейблы на ноде то уже запущенный под или переезжает на ноду если такие лейблы есть или умирает.
  • Taint and Tolerations — Для установка подов на необходимую ноду. Но он не может гарантировать что поды попадут на другую ноду котороу мы не хотим, для таких сложных моментов нужно применять совместно с Affinity
  • StaticPod — Запуск подов без кластера,
    • Kubelet ищет манивесты в папке установленной в параметре  staticPodPath и запускает их на своей ноде
    • Так запускаются все системные контейнеры
    • Есть отличия в синтаксисе манифестов!
    • Узнать где лежат конфига — посмотреть через параметры запускаемого процесса kubelet
    • Не забываем смотреть journalctl -u kubelet в случае проблем запуска статик пода.
Update
    • Rolling  — Default and 1:1
        • MaxSurge — Колличество или процент новых созданных подов
        • MaxUnavailable -Колличество или процент терминированных подов
    • Recriate — Пересоздание всех подов сразу
Controller Manager
    • Node Monitor Period = 5 s
    • Node Monitor Grace Period = 40 s (Ставить пометку на ноду как недоступная)
    • Pod Evication Timepot = 5m (Перенос пода на другую ноду при недоступности)
Kube Sheduler
    • Выбирает нужную ноду для пода.
Cli Command
https://kubernetes.io/docs/reference/kubectl/conventions/
Change NS
kubectl config set-context $(kubectl config current-context) —namespace=dev
Set image
kubectl set image deployment my-nginx my-nginx=nginx:1.12.0
--dry-run: By default as soon as the command is run, the resource will be created. If you simply want to test your command , use the --dry-run=client option. This will not create the resource, instead, tell you whether the resource can be created and if your command is right. -o yaml: This will output the resource definition in YAML format on screen. Use the above two in combination to generate a resource definition file quickly, that you can then modify and create resources as required, instead of creating the files from scratch.

POD

Create an NGINX Pod k run custom-nginx —image=nginx —labels tier=custom-nginx —port=8080 Generate POD Manifest YAML file (-o yaml). Don’t create it(—dry-run) kubectl run nginx --image=nginx --dry-run=client -o yaml

Deployment

Create a deployment kubectl create deployment --image=nginx nginx Generate Deployment YAML file (-o yaml). Don’t create it(—dry-run) kubectl create deployment --image=nginx nginx --dry-run=client -o yaml Generate Deployment with 4 Replicas kubectl create deployment nginx --image=nginx --replicas=4 You can also scale a deployment using the kubectl scale command. kubectl scale deployment nginx --replicas=4 Another way to do this is to save the YAML definition to a file and modify kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > nginx-deployment.yaml You can then update the YAML file with the replicas or any other field before creating the deployment.

Service

Create a Service named redis-service of type ClusterIP to expose pod redis on port 6379 kubectl expose pod redis --port=6379 --name redis-service --dry-run=client -o yaml (This will automatically use the pod’s labels as selectors) Or kubectl create service clusterip redis --tcp=6379:6379 --dry-run=client -o yaml (This will not use the pods labels as selectors, instead it will assume selectors as app=redis. You cannot pass in selectors as an option. So it does not work very well if your pod has a different label set. So generate the file and modify the selectors before creating the service) Create a Service named nginx of type NodePort to expose pod nginx’s port 80 on port 30080 on the nodes: kubectl expose pod nginx --type=NodePort --port=80 --name=nginx-service --dry-run=client -o yaml (This will automatically use the pod’s labels as selectors, but you cannot specify the node port. You have to generate a definition file and then add the node port in manually before creating the service with the pod.) Or kubectl create service nodeport nginx --tcp=80:80 --node-port=30080 --dry-run=client -o yaml (This will not use the pods labels as selectors) Both the above commands have their own challenges. While one of it cannot accept a selector the other cannot accept a node port. I would recommend going with the kubectl expose command. If you need to specify a node port, generate a definition file using the same command and manually input the nodeport before creating the service
  • k get pods -l env=dev  — Поиск по лейблу
  • k get pods -l env=dev —node-headers | wc -l — Колличество подов с определенным тегом
  • k get all -l env=dev —node-headers
  • kubectl get pods --show-labels
  • Taint
    • k taint node node01 spray=mortein:NoSchedule — Create taint on node
    • k taint node controlplane node-role.kubernetes.io/control-plane:NoSchedule — Delete Taint
  • k set image pod/nginx nginx=mosquito:latest — Change image in pod k label nodes node01 color=blue — Add label on node
  • Cordon
    • k drain node01 — Вывод ноды из рабочего состояния и перенос подов на др ноды
    • k uncordon node01 — Возвращение ноды из нерабочего состояния
    • k cordon node01— Установить запрет на запуск новых подов

Reference:

https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands https://kubernetes.io/docs/reference/kubectl/conventions/
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  -  image: nginx
     name: nginx
  nodeName: controlplane

Добавить комментарий 0