This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
стратегии_деплоя_в_kubernetes [2025/02/24 11:46] val [Шаг 5. canary deployment with Gateway API] |
стратегии_деплоя_в_kubernetes [2025/03/24 18:06] (current) val [Шаг 6. canary deployment with Istio VirtualService] |
||
|---|---|---|---|
| Line 17: | Line 17: | ||
| ===== Запись вебинара ===== | ===== Запись вебинара ===== | ||
| - | * Тэги: | + | * Тэги: deployment rollout, canary deployment, ingress annotations, Kubernetes Gateway API, Istio Service Mesh, kiali, nginx proxy header |
| + | * https://rutube.ru/video/private/45160ea603c4f541cd11ebcc3fdf5109/ | ||
| + | * https://youtu.be/uEpEDk8EWSg | ||
| ===== Методическая подготовка ===== | ===== Методическая подготовка ===== | ||
| - | ==== В паузах рассказать про ==== | ||
| - | |||
| - | * | ||
| ===== Шаг 1. Что у нас есть для начала ===== | ===== Шаг 1. Что у нас есть для начала ===== | ||
| Line 286: | Line 285: | ||
| * [[https://tetrate.io/blog/header-based-routing-in-istio-without-header-propagation/|Header-Based Routing in Istio without Header Propagation]] | * [[https://tetrate.io/blog/header-based-routing-in-istio-without-header-propagation/|Header-Based Routing in Istio without Header Propagation]] | ||
| <code> | <code> | ||
| - | ~/istio-1.24.3# kubectl apply -f samples/addons | + | kube1:~/istio-1.24.3# kubectl apply -f samples/addons |
| - | # kubectl get pods -n istio-system | + | kube1# kubectl get pods -n istio-system |
| /home/mobaxterm> ssh root@192.168.13.221 -X | /home/mobaxterm> ssh root@192.168.13.221 -X | ||
| - | # istioctl dashboard kiali & | + | kube1# istioctl dashboard kiali & |
| - | # firefox & | + | kube1# firefox & |
| или | или | ||
| cmder> ssh -L20001:localhost:20001 root@192.168.13.221 | cmder> ssh -L20001:localhost:20001 root@192.168.13.221 | ||
| - | # kubectl port-forward svc/kiali 20001:20001 -n istio-system | + | kube1# kubectl port-forward svc/kiali 20001:20001 -n istio-system |
| или | или | ||
| Line 305: | Line 304: | ||
| http://localhost:20001/ | http://localhost:20001/ | ||
| - | kubectl delete ns my-ns; kubectl create ns my-ns | + | kube1# kubectl delete ns my-ns; kubectl create ns my-ns |
| - | kubectl label namespace my-ns istio-injection=enabled | + | kube1# kubectl label namespace my-ns istio-injection=enabled |
| - | kubectl get ns --show-labels | + | kube1# kubectl get ns --show-labels |
| - | kube1:~/gowebd-k8s# cat my-webd-deployment-v1-v2.yaml | + | kube1# cat my-webd-deployment-v1-v2.yaml |
| </code><code> | </code><code> | ||
| apiVersion: apps/v1 | apiVersion: apps/v1 | ||
| Line 351: | Line 350: | ||
| image: server.corp13.un:5000/student/gowebd:ver1.2 | image: server.corp13.un:5000/student/gowebd:ver1.2 | ||
| </code><code> | </code><code> | ||
| - | # kubectl apply -f my-webd-deployment-v1-v2.yaml -n my-ns | + | kube1# kubectl apply -f my-webd-deployment-v1-v2.yaml -n my-ns |
| - | # kubectl -n my-ns describe pod my-webd-v1-<TAB> | grep istio | + | kube1# kubectl -n my-ns describe pod my-webd-v1-<TAB> | grep istio |
| - | # cat my-webd-service.yaml | + | kube1# cat my-webd-service.yaml |
| </code><code> | </code><code> | ||
| apiVersion: v1 | apiVersion: v1 | ||
| Line 369: | Line 368: | ||
| name: http #need for istio | name: http #need for istio | ||
| </code><code> | </code><code> | ||
| - | # kubectl apply -f my-webd-service.yaml -n my-ns | + | kube1# kubectl apply -f my-webd-service.yaml -n my-ns |
| | | ||
| - | # kubectl get svc -n istio-system | grep ingr | + | kube1# kubectl get svc -n istio-system | grep ingr |
| istio-ingressgateway LoadBalancer 10.233.37.214 192.168.13.65 15021:31547/TCP,80:32173/TCP,443:31308/TCP 19h | istio-ingressgateway LoadBalancer 10.233.37.214 192.168.13.65 15021:31547/TCP,80:32173/TCP,443:31308/TCP 19h | ||
| - | kube1:~/gowebd-k8s# cat my-webd-istio-gateway.yaml | + | kube1# cat my-webd-istio-gateway.yaml |
| </code><code> | </code><code> | ||
| apiVersion: networking.istio.io/v1 | apiVersion: networking.istio.io/v1 | ||
| Line 393: | Line 392: | ||
| # - "*" | # - "*" | ||
| </code><code> | </code><code> | ||
| - | # kubectl apply -f my-webd-istio-gateway.yaml -n my-ns | + | kube1# kubectl apply -f my-webd-istio-gateway.yaml -n my-ns |
| - | # cat my-webd-destrul.yaml | + | kube1# cat my-webd-destrul.yaml |
| </code><code> | </code><code> | ||
| apiVersion: networking.istio.io/v1alpha3 | apiVersion: networking.istio.io/v1alpha3 | ||
| Line 411: | Line 410: | ||
| version: v2-lab | version: v2-lab | ||
| </code><code> | </code><code> | ||
| - | # kubectl apply -f my-webd-destrul.yaml -n my-ns | + | kube1# kubectl apply -f my-webd-destrul.yaml -n my-ns |
| - | # cat virtserv-after-gateway.yaml | + | kube1# cat virtserv-after-gateway.yaml |
| </code><code> | </code><code> | ||
| apiVersion: networking.istio.io/v1alpha3 | apiVersion: networking.istio.io/v1alpha3 | ||
| Line 428: | Line 427: | ||
| # match: | # match: | ||
| # - headers: | # - headers: | ||
| - | ## x-forwarded-for: | + | # x-forwarded-for: |
| - | ## regex: "192.168.13.*" | + | # regex: "192.168.13.*" |
| - | # x-my-version: | + | ## x-my-version: |
| - | # exact: canary | + | ## exact: canary |
| # route: | # route: | ||
| # - destination: | # - destination: | ||
| Line 452: | Line 451: | ||
| weight: 10 | weight: 10 | ||
| </code><code> | </code><code> | ||
| - | # kubectl apply -f virtserv-after-gateway.yaml -n my-ns | + | kube1# kubectl apply -f virtserv-after-gateway.yaml -n my-ns |
| | | ||
| - | # while true; do curl 192.168.13.65 -H "Host: gowebd.corp13.un"; sleep 0.1; done | + | kube1# while true; do curl 192.168.13.65 -H "Host: gowebd.corp13.un"; sleep 0.1; done |
| - | # cat frontend.yaml | + | kube1# cat frontend.yaml |
| </code><code> | </code><code> | ||
| apiVersion: apps/v1 | apiVersion: apps/v1 | ||
| Line 558: | Line 557: | ||
| version: v2 | version: v2 | ||
| </code><code> | </code><code> | ||
| - | # cat virtserv-after-gateway.yaml | + | kube1# kubectl apply -f frontend.yaml -n my-ns |
| + | |||
| + | kube1# cat virtserv-after-gateway.yaml | ||
| </code><code> | </code><code> | ||
| ... | ... | ||
| Line 572: | Line 573: | ||
| ... | ... | ||
| </code><code> | </code><code> | ||
| - | # cat my-webd-virtserv-src-lab.yaml | + | kube1# kubectl apply -f virtserv-after-gateway.yaml -n my-ns |
| + | |||
| + | kube1# while true; do curl 192.168.13.65 -H "Host: gowebd.corp13.un"; sleep 0.1; done | ||
| + | |||
| + | kube1# cat my-webd-virtserv-src-lab.yaml | ||
| </code><code> | </code><code> | ||
| apiVersion: networking.istio.io/v1alpha3 | apiVersion: networking.istio.io/v1alpha3 | ||
| Line 605: | Line 610: | ||
| number: 80 | number: 80 | ||
| weight: 100 | weight: 100 | ||
| + | </code><code> | ||
| + | kube1# kubectl apply -f my-webd-virtserv-src-lab.yaml -n my-ns | ||
| + | |||
| + | kube1# while true; do curl 192.168.13.65 -H "Host: gowebd.corp13.un"; sleep 0.1; done | ||
| </code> | </code> | ||
| - | * [[https://istio.io/latest/docs/tasks/observability/logs/access-log/|Envoy Access Logs]] | + | ==== Добавление журналов ==== |
| - | <code> | + | * [[https://istio.io/latest/docs/tasks/observability/logs/access-log/|Envoy Access Logs ... Default access log format]] |
| - | # curl 192.168.13.65 -H "Host: gowebd.corp13.un" -H "x-my-version: canary" | + | |
| - | # cat telemetry.yaml | + | <code> |
| + | kube1# vim virtserv-after-gateway.yaml | ||
| + | </code><code> | ||
| + | ... | ||
| + | x-forwarded-for: | ||
| + | regex: "192.168.13.*" | ||
| + | ... | ||
| + | - {} | ||
| + | route: | ||
| + | - destination: | ||
| + | host: frontend | ||
| + | subset: v1 | ||
| + | </code><code> | ||
| + | kube1# cat telemetry.yaml | ||
| + | </code><code> | ||
| apiVersion: telemetry.istio.io/v1alpha1 | apiVersion: telemetry.istio.io/v1alpha1 | ||
| kind: Telemetry | kind: Telemetry | ||
| Line 623: | Line 645: | ||
| - name: Envoy | - name: Envoy | ||
| </code><code> | </code><code> | ||
| - | # kubectl apply -f telemetry.yaml -n istio-system | + | kube1# kubectl apply -f telemetry.yaml -n istio-system |
| - | # curl 192.168.13.65 -H "Host: gowebd.corp13.un" -H "x-forwarded-for: 192.168.13.10" | + | kube1# curl 192.168.13.65 -H "Host: gowebd.corp13.un" -H "x-forwarded-for: 192.168.13.10" |
| - | # kubectl -n my-ns logs -l app=my-webd-lab -c istio-proxy -f | + | kube1# kubectl -n my-ns logs -l app=my-webd-lab -c istio-proxy -f |
| + | kube1# kubectl -n my-ns logs pods/my-webd-v2-<TAB> -c istio-proxy -f | ||
| + | kube1# kubectl -n my-ns logs pods/frontend-v2-<TAB> -c istio-proxy -f | ||
| + | </code><code> | ||
| + | kube1# vim virtserv-after-gateway.yaml | ||
| + | </code><code> | ||
| + | ... | ||
| + | # x-my-version: | ||
| + | # exact: canary | ||
| + | ... | ||
| + | </code><code> | ||
| + | kube1# curl 192.168.13.65 -H "Host: gowebd.corp13.un" -H "x-my-version: canary" | ||
| + | |||
| + | gate# systemctl disable haproxy --now | ||
| - | # cat /etc/nginx/sites-available/gowebd | + | gate# cat /etc/nginx/sites-available/gowebd |
| </code><code> | </code><code> | ||
| server { | server { | ||
| listen 80; | listen 80; | ||
| server_name gowebd.corp13.un; | server_name gowebd.corp13.un; | ||
| - | return 301 https://gowebd.corp13.un$request_uri; | + | return 301 https://gowebd.corp13.un:443$request_uri; |
| } | } | ||
| Line 648: | Line 683: | ||
| proxy_set_header Host $host; | proxy_set_header Host $host; | ||
| proxy_set_header X-Forwarded-For $remote_addr; | proxy_set_header X-Forwarded-For $remote_addr; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | server { | ||
| + | listen 8080; | ||
| + | server_name gowebd.corp13.un; | ||
| + | return 301 https://gowebd.corp13.un:8443$request_uri; | ||
| + | } | ||
| + | |||
| + | server { | ||
| + | listen 8443 ssl; | ||
| + | server_name gowebd.corp13.un; | ||
| + | ssl_certificate /root/gowebd.crt; | ||
| + | ssl_certificate_key /root/gowebd.key; | ||
| + | |||
| + | location / { | ||
| + | proxy_pass http://192.168.13.65; | ||
| + | proxy_http_version 1.1; | ||
| + | proxy_set_header Host $host; | ||
| + | proxy_set_header X-Forwarded-For $remote_addr; | ||
| + | proxy_set_header X-My-Version "canary"; | ||
| } | } | ||
| } | } | ||
| </code><code> | </code><code> | ||
| - | server.corp13.un:~# curl https://gowebd.corp13.un | + | gate# systemctl enable nginx --now |
| + | |||
| + | gate.corp13.un:~# cat /etc/iptables/rules.v4 | ||
| + | ... | ||
| + | :POSTROUTING ACCEPT [0:0] | ||
| + | -A PREROUTING -d 172.16.1.13/32 -i eth1 -p udp -m udp --dport 53 -j DNAT --to-destination 192.168.13.10:53 | ||
| + | -A PREROUTING -s 172.16.1.113/32 -d 172.16.1.13/32 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.1.13:8080 | ||
| + | -A PREROUTING -s 172.16.1.113/32 -d 172.16.1.13/32 -p tcp -m tcp --dport 443 -j DNAT --to-destination 172.16.1.13:8443 | ||
| + | -A POSTROUTING -s 192.168.13.0/24 -o eth1 -j MASQUERADE | ||
| + | COMMIT | ||
| + | ... | ||
| + | gate.corp13.un:~# iptables-restore /etc/iptables/rules.v4 | ||
| + | |||
| + | server# curl https://gowebd.corp13.un | ||
| - | winclient> https://gowebd.corp13.un | + | win client> https://gowebd.corp13.un |
| </code> | </code> | ||
| ===== Вопросы? ===== | ===== Вопросы? ===== | ||