brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jul 11. 2021

쿠버1탄-22. 쿠버네티스 - 카나리 업그레이드

다음은 쿠버네티스 스터디 자료를 참고해  정리한 내용입니다.


카나리 업그레이드


<1>   pod 생성

<2>  생성 확인 

<3> 실습1  업그레이드

<4> 삭제 


쿠버네티스-도메인 없이 kops로 aws쿠버설치

https://brunch.co.kr/@topasvga/1681



<1>   pod 생성


1

cat << EOF > canary-svc1-pod.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: dp-v1

spec:

  replicas: 3

  selector:

    matchLabels:

      app: svc-v1

  template:

    metadata:

      labels:

        app: svc-v1

    spec:

      containers:

      - name: pod-v1

        image: k8s.gcr.io/echoserver:1.5

        ports:

        - containerPort: 8080

---

apiVersion: v1

kind: Service

metadata:

  name: svc-v1

spec:

  ports:

    - name: web-port

      port: 9001

      targetPort: 8080

  selector:

    app: svc-v1

EOF


cat << EOF > canary-svc2-pod.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: dp-v2

spec:

  replicas: 3

  selector:

    matchLabels:

      app: svc-v2

  template:

    metadata:

      labels:

        app: svc-v2

    spec:

      containers:

      - name: pod-v2

        image: k8s.gcr.io/echoserver:1.6

        ports:

        - containerPort: 8080

---

apiVersion: v1

kind: Service

metadata:

  name: svc-v2

spec:

  ports:

    - name: web-port

      port: 9001

      targetPort: 8080

  selector:

    app: svc-v2

EOF



<2>  생성 확인 


1

터미널1

watch -d 'kubectl get pod -n ingress-nginx -o wide -l app.kubernetes.io/component=controller; echo; kubectl get svc -n ingress-nginx; echo; kubectl ingress-nginx ingresses; echo ;kubectl get ingress,ep;'


생성

kubectl apply -f canary-svc1-pod.yaml

kubectl apply -f canary-svc2-pod.yaml


2

서비스와 엔드포인트 생성됨

NAME                   ENDPOINTS                                                      AGE

endpoints/kubernetes   172.20.60.135:443                                              29m

endpoints/svc-v1       100.119.191.136:8080,100.119.191.137:8080,100.99.251.10:8080   3m39s

endpoints/svc-v2       100.119.191.138:8080,100.99.251.11:8080,100.99.251.12:8080     3m23s


NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE

service/kubernetes   ClusterIP   100.64.0.1       <none>        443/TCP    29m

service/svc-v1       ClusterIP   100.65.128.159   <none>        9001/TCP   3m39s

service/svc-v2       ClusterIP   100.68.68.167    <none>        9001/TCP   3m23s



확인

kubectl get svc

kubectl get endpoints


3

파드 버전 확인

for pod in $(kubectl get pod -o wide -l app=svc-v1 |awk 'NR>1 {print $6}'); do curl -s $pod:8080 | egrep '(Hostname|nginx)'; done

Hostname: dp-v1-cdd8dc687-5n4pb

        server_version=nginx: 1.13.0 - lua: 10008

Hostname: dp-v1-cdd8dc687-vnrdm

        server_version=nginx: 1.13.0 - lua: 10008

Hostname: dp-v1-cdd8dc687-z26qp

        server_version=nginx: 1.13.0 - lua: 10008

// 0 버전 


for pod in $(kubectl get pod -o wide -l app=svc-v2 |awk 'NR>1 {print $6}'); do curl -s $pod:8080 | egrep '(Hostname|nginx)'; done


Hostname: dp-v2-785f69bd6-c989j

        server_version=nginx: 1.13.1 - lua: 10008

Hostname: dp-v2-785f69bd6-jwjg6

        server_version=nginx: 1.13.1 - lua: 10008

Hostname: dp-v2-785f69bd6-kpb5x

        server_version=nginx: 1.13.1 - lua: 10008

// 1 버전임


4

watch -d 'kubectl get pod -n ingress-nginx -o wide -l app.kubernetes.io/component=controller; echo; kubectl get svc -n ingress-nginx; echo; kubectl ingress-nginx ingresses; echo ;kubectl get pod,ingress,ep,svc,deploy;'


// pod, ingress, endpoint, 서비스,디플로이먼트 모니터링


NAME  READY STATUS  RESTARTS  AGE  IP  NODE NOMINATED NODE   READINESS GATES

ingress-nginx-controller-584dc4797b-z5g29   1/1     Running   0          16h   100.112.248.194   ip-172-20-60-135.ap-northeast-1.compute.internal  <none>           <none>


NAME                                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE

ingress-nginx-controller  NodePort  100.71.111.209  <none>   80:30294/TCP,443:32625/TCP   16h

ingress-nginx-controller-admission  ClusterIP   100.65.182.94   <none>   443/TCP                16h


INGRESS NAME   HOST+PATH   ADDRESSES   TLS   SERVICE   SERVICE PORT   ENDPOINTS


NAME                        READY   STATUS    RESTARTS   AGE

pod/dp-v1-cdd8dc687-5n4pb   1/1     Running   0          12m

pod/dp-v1-cdd8dc687-vnrdm   1/1     Running   0          12m

pod/dp-v1-cdd8dc687-z26qp   1/1     Running   0          12m

pod/dp-v2-785f69bd6-c989j   1/1     Running   0          11m

pod/dp-v2-785f69bd6-jwjg6   1/1     Running   0          11m

pod/dp-v2-785f69bd6-kpb5x   1/1     Running   0          11m


NAME                   ENDPOINTS                                                      AGE

endpoints/kubernetes   172.20.60.135:443                                              38m

endpoints/svc-v1       100.119.191.136:8080,100.119.191.137:8080,100.99.251.10:8080   12m

endpoints/svc-v2       100.119.191.138:8080,100.99.251.11:8080,100.99.251.12:8080     11m


NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE

service/kubernetes   ClusterIP   100.64.0.1       <none>        443/TCP    38m

service/svc-v1       ClusterIP   100.65.128.159   <none>        9001/TCP   12m

service/svc-v2       ClusterIP   100.68.68.167    <none>        9001/TCP   11m


NAME                    READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/dp-v1   3/3     3            3           12m

deployment.apps/dp-v2   3/3     3            3           11m





<3> 실습1 -  업그레이드


1

인그레스 ~



cat << EOF > canary-ingress1.yaml

apiVersion: networking.k8s.io/v1beta1

kind: Ingress

metadata:

  name: ingress-canary-v1

  annotations:

    kubernetes.io/ingress.class: "nginx"

spec:

  rules:

  - host: dkos.com

    http:

      paths:

      - backend:

          serviceName: svc-v1

          servicePort: 8080

EOF


2

cat << EOF > canary-ingress2.yaml

apiVersion: networking.k8s.io/v1beta1

kind: Ingress

metadata:

  name: ingress-canary-v2

  annotations:

    kubernetes.io/ingress.class: "nginx"

    nginx.ingress.kubernetes.io/canary: "true"

    nginx.ingress.kubernetes.io/canary-weight: "10"

spec:

  rules:

  - host: dkos.com

    http:

      paths:

      - backend:

          serviceName: svc-v2

          servicePort: 8080

EOF



3

업그레이드 확인


터미널1

watch -d 'kubectl get pod -n ingress-nginx -o wide -l app.kubernetes.io/component=controller; echo; kubectl get svc -n ingress-nginx; echo; kubectl ingress-nginx ingresses; echo ;kubectl get ingress,ep;'


watch -d 'kubectl get pod -n ingress-nginx -o wide -l app.kubernetes.io/component=controller; echo; kubectl get svc -n ingress-nginx; echo; kubectl ingress-nginx ingresses; echo ;kubectl get ingress,ep,svc;'


4

masterseo.com 로 접속 도메인 변경

생성

sed -i 's/dkos.com/masterseo.com/g' canary-ingress1.yaml

sed -i 's/dkos.com/masterseo.com/g' canary-ingress2.yaml

kubectl apply -f canary-ingress1.yaml

kubectl apply -f canary-ingress2.yaml


5

접속 테스트

echo $MYDOMAIN1

echo $IngHttp


curl -s $MYDOMAIN1:$IngHttp

curl -s $MYDOMAIN1:$IngHttp | grep nginx


for i in {1..100};  do curl -s $MYDOMAIN1:$IngHttp | grep nginx ; done | sort | uniq -c | sort -nr

for i in {1..1000}; do curl -s $MYDOMAIN1:$IngHttp | grep nginx ; done | sort | uniq -c | sort -nr


9 대 1

for i in {1..100};  do curl -s $MYDOMAIN1:$IngHttp | grep nginx ; done | sort | uniq -c | sort -nr

     92         server_version=nginx: 1.13.0 - lua: 10008

      8         server_version=nginx: 1.13.1 - lua: 10008




while true; do curl -s --connect-timeout 1 $MYDOMAIN1:$IngHttp | grep Hostname ; echo "--------------" ; date "+%Y-%m-%d %H:%M:%S" ; sleep 1; done


Hostname: dp-v1-cdd8dc687-5n4pb

--------------

2021-07-12 05:57:28

Hostname: dp-v2-785f69bd6-c989j

--------------

2021-07-12 05:57:29

Hostname: dp-v1-cdd8dc687-vnrdm



6

비율 조정

10 % 를  50%로 변경


kubectl get ingress ingress-canary-v2 -o yaml | sed -e "s/weight: \"10\"/weight: \"50\"/" | kubectl apply -f -


접속 테스트

for i in {1..100};  do curl -s $MYDOMAIN1:$IngHttp | grep nginx ; done | sort | uniq -c | sort -nr

for i in {1..1000}; do curl -s $MYDOMAIN1:$IngHttp | grep nginx ; done | sort | uniq -c | sort -nr

     58         server_version=nginx: 1.13.1 - lua: 10008

     42         server_version=nginx: 1.13.0 - lua: 10008




<4> 삭제 


kubectl delete deployments,svc,ingress --all   



다음과정

https://brunch.co.kr/@topasvga/1711


감사합니다.

매거진의 이전글 쿠버1탄-21. 쿠버네티스 - Host기반 라우팅
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari