무중단 Blue/Green 배포 시나리오를 실습해 본다.

#mkdir docker/app #@폴더 생성
#cd docker/app
#vi Dockerfile #@Dockerfile 생성
FROM nginx
ADD index.html /usr/share/nginx/html #@컨테이너 루트도큐먼트 위치에 복사 하겠다.

 

#vi index.html 
This is app v1 test…
#docker build -t app:v1 . #@.은 현재 Dockerfile의 위치
	root@ip-172-31-4-27:~/docker/app# docker build -t app:v1 .
	Sending build context to Docker daemon  3.072kB
	Step 1/2 : FROM nginx
	 ---> bc9a0695f571
	Step 2/2 : ADD index.html /usr/share/nginx/html
	 ---> ba8e7526e7b9
	Successfully built ba8e7526e7b9
	Successfully tagged app:v1

 

#vi index.html 
This is app v2 test...
#docker build -t app:v2 .
	root@ip-172-31-4-27:~/docker/app# docker build -t app:v2 .
	Sending build context to Docker daemon  3.072kB
	Step 1/2 : FROM nginx
	 ---> bc9a0695f571
	Step 2/2 : ADD index.html /usr/share/nginx/html
	 ---> 4eaf1726cc8b
	Successfully built 4eaf1726cc8b
	Successfully tagged app:v2

 

#docker login #@아이디 패스워드 입력 물어본다
	root@ip-172-31-4-27:~/docker/app# docker login
	Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
	Username: nasamjang02	    
	Password: 
	WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
	Configure a credential helper to remove this warning. See
	https://docs.docker.com/engine/reference/commandline/login/#credentials-store

 

#docker tag app:v1 nasamjang02/app:v1  #@나의 Dockerhub에 업로드 하겠다
			원본		링크테크

 

#docker push nasamjang02/app:v1
	root@ip-172-31-4-27:~/docker/app# docker push nasamjang02/app:v1
	The push refers to repository [docker.io/nasamjang02/app]
	54d08aacb5be: Pushed 
	7e914612e366: Mounted from library/nginx 
	f790aed835ee: Mounted from library/nginx 
	850c2400ea4d: Mounted from library/nginx 
	7ccabd267c9f: Mounted from library/nginx 
	f5600c6330da: Mounted from library/nginx 
	v1: digest: sha256:e2d9e2d5b24789e77bd93d2ec7aba7a862c92c7664bc44a33c11fe6395554484 size: 1569

 

#docker tag app:v2 nasamjang02/app:v2
#docker push nasamjang02/app:v2
	root@ip-172-31-4-27:~/docker/app# docker push nasamjang02/app:v2
	The push refers to repository [docker.io/nasamjang02/app]
	b52e0c763eb7: Pushed 
	7e914612e366: Layer already exists 
	f790aed835ee: Layer already exists 
	850c2400ea4d: Layer already exists 
	7ccabd267c9f: Layer already exists 
	f5600c6330da: Layer already exists 
	v2: digest: sha256:f9f42c87d39a2822b11870e75bcff6acaca60ae36dd753019ccd7614333bca3e size: 1569

 

#kubectl create deploy blue --image nasamjang02/app:v1
						#@블루라는 서비스 v1으로 시작
	root@ip-172-31-4-27:~/docker/app# kubectl create deploy blue --image nasamjang02/app:v1
	deployment.apps/blue created

 

#kubectl expose deployment blue --port=80 --name app #@외부에서 접근가능 하도록 expose 설정
	root@ip-172-31-4-27:~/docker/app# kubectl expose deployment blue --port=80 --name app
	service/app exposed

#kubectl get svc
	root@ip-172-31-4-27:~/docker/app# kubectl get svc
	NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
	app          ClusterIP   10.111.169.205   <none>        80/TCP    16s
	kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP   25h

#curl 10.110.252.32:80 (service IP)
	root@ip-172-31-4-27:~/docker/app# curl 10.111.169.205:80
	This is app v1 test…

This is app v1 test...
#kubectl create deploy green --image nasamjang02/app:v2
	root@ip-172-31-4-27:~/docker/app# kubectl create deploy green --image nasamjang02/app:v2
	deployment.apps/green created
	
	NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
	deployment.apps/blue    1/1     1            1           2m9s
	deployment.apps/green   1/1     1            1           21s

	NAME                               DESIRED   CURRENT   READY   AGE
	replicaset.apps/blue-6c88d658db    1         1         1       2m9s
	replicaset.apps/green-5f846655d4   1         1         1       21s

	NAME                         READY   STATUS    RESTARTS   AGE
	pod/blue-6c88d658db-2lvqn    1/1     Running   0          2m9s
	pod/green-5f846655d4-8blcs   1/1     Running   0          21s

	
#curl green-pod-ip
This is app v2 test...
#kubectl get deploy --show-labels #@labels 확인
	root@ip-172-31-4-27:~/docker/app# kubectl get deploy --show-labels
	NAME    READY   UP-TO-DATE   AVAILABLE   AGE     LABELS
	blue    1/1     1            1           3m59s   app=blue
	green   1/1     1            1           2m11s   app=green

#kubectl set selector svc app app=green #@app=green으로 바꿔준다
	root@ip-172-31-4-27:~/docker/app# kubectl set selector svc app app=green
	service/app selector updated
#kubectl get ep #@Endpoint 확인
	root@ip-172-31-4-27:~/docker/app# kubectl get ep
	NAME         ENDPOINTS          AGE
	app          192.168.82.26:80   3m47s
	kubernetes   172.31.4.27:6443   26h
	
#curl 10.108.70.86  (service IP)
This is app v2 test...
	root@ip-172-31-4-27:~/docker/app# curl 192.168.82.26:80
	This is app v2 test…
	
	다시 blue로 변경
	root@ip-172-31-4-27:~/docker/app# kubectl set selector svc app app=blue
	service/app selector updated

	endpoint 확인
	root@ip-172-31-4-27:~/docker/app# kubectl get ep
	NAME         ENDPOINTS          AGE
	app          192.168.82.25:80   4m57s
	kubernetes   172.31.4.27:6443   26h
	
	curl 시도
	root@ip-172-31-4-27:~/docker/app# curl 192.168.82.25:80
	This is app v1 test…


kubectl delete deployments.apps blue
	root@ip-172-31-4-27:~# kubectl delete deployments.apps blue
	deployment.apps "blue" deleted
	root@ip-172-31-4-27:~# kubectl delete deployments.apps green
	deployment.apps "green" deleted

+ Recent posts