brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Feb 22. 2023

14. 오라클 클라우드-쿠버네티스-카나리 업그레이드

<1> 카나리 업그레이드

<2> 인그레스 생성과 카나리 배포 조정



<1> 카나리 업그레이드


1

파드 생성


topasvga@cloudshell:~ (ap-seoul-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


topasvga@cloudshell:~ (ap-seoul-1)$ 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

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f canary-svc1-pod.yaml

deployment.apps/dp-v1 created

service/svc-v1 created



topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f canary-svc2-pod.yaml

deployment.apps/dp-v2 created

service/svc-v2 created



3

생성 확인

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get svc

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

kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP    88s

svc-v1       ClusterIP   10.96.99.120    <none>        9001/TCP   19s

svc-v2       ClusterIP   10.96.191.129   <none>        9001/TCP   15s


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get endpoints

NAME             ENDPOINTS                                              AGE

oracle.com-oci   <none>                                                 15h

svc-v1           10.244.0.173:8080,10.244.0.72:8080,10.244.0.73:8080    23s

svc-v2           10.244.0.174:8080,10.244.0.175:8080,10.244.0.74:8080   18s



4

파드 버전 확인 ?

현재 버전은 1.13.0

topasvga@cloudshell:~ (ap-seoul-1)$ 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

^C


현재 버전은 1.13.1

topasvga@cloudshell:~ (ap-seoul-1)$ 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

^C



5

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pod,ingress,ep,svc,deploy

NAME                         READY   STATUS    RESTARTS   AGE

pod/dp-v1-66cbf74c56-5n2h9   1/1     Running   0          3m49s

pod/dp-v1-66cbf74c56-mkmld   1/1     Running   0          3m49s

pod/dp-v1-66cbf74c56-thxg2   1/1     Running   0          3m49s

pod/dp-v2-94cb4ffc7-2rncn    1/1     Running   0          3m45s

pod/dp-v2-94cb4ffc7-6clrf    1/1     Running   0          3m45s

pod/dp-v2-94cb4ffc7-c5qvf    1/1     Running   0          3m45s


NAME                       ENDPOINTS                                              AGE

endpoints/oracle.com-oci   <none>                                                 15h

endpoints/svc-v1           10.244.0.173:8080,10.244.0.72:8080,10.244.0.73:8080    3m49s

endpoints/svc-v2           10.244.0.174:8080,10.244.0.175:8080,10.244.0.74:8080   3m44s


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

service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP    4m58s

service/svc-v1       ClusterIP   10.96.99.120    <none>        9001/TCP   3m49s

service/svc-v2       ClusterIP   10.96.191.129   <none>        9001/TCP   3m45s


NAME                    READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/dp-v1   3/3     3            3           3m49s

deployment.apps/dp-v2   3/3     3            3           3m45s




<2> 인그레스 생성과 카나리 배포 조정


1

topasvga@cloudshell:~ (ap-seoul-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

topasvga@cloudshell:~ (ap-seoul-1)$ 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

topasvga@cloudshell:~ (ap-seoul-1)$ sed -i 's/dkos.com/masterseo.com/g' canary-ingress1.yaml



topasvga@cloudshell:~ (ap-seoul-1)$ sed -i 's/dkos.com/masterseo.com/g' canary-ingress2.yaml



4

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f canary-ingress1.yaml

error: resource mapping not found for name: "ingress-canary-v1" namespace: "" from "canary-ingress1.yaml": no matches for kind "Ingress" in version "networking.k8s.io/v1beta1"

ensure CRDs are installed first



topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f canary-ingress2.yaml

error: resource mapping not found for name: "ingress-canary-v2" namespace: "" from "canary-ingress2.yaml": no matches for kind "Ingress" in version "networking.k8s.io/v1beta1"

ensure CRDs are installed first



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


10

비율 조정

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


11

kubectl delete deployments,svc,ingress --all   



감사합니다.

브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari