...
# Define variables AKS_Name="osd2023KORzeroaksdemotdgzeroaksdemo" ACR_Name="osd2023KORzeroacrdemotdgzeroacrdemo" RG_Name="RG-TDG-CMS-OSD20232023-AKSDemo" # Get AKS credentials az aks get-credentials -g $RG_Name -n $AKS_Name # Get Node Info kubectl get node |
Application 배포 및 검증
ACR 이미지 등록
별도 터미널 창을 열어 이미지 태그 및 푸시
...
Code Block |
---|
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ AKS_Name="tdgzeroaksdemo"ACR_Name="tdgzeroacrdemo"RG_Name="RG-TDG-CMS-2023-AKSDemo"
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ AKS_Name="tdgzeroaksdemo"
ACR_Name="tdgzeroacrdemo"
RG_Name="RG-TDG-CMS-2023-AKSDemo"
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ az aks get-credentials -g $RG_Name -n $AKS_Name
Merged "tdgzeroaksdemo" as current context in /home/zerobig/.kube/config
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ kubectl get node
NAME STATUS ROLES AGE VERSION
aks-default-34060743-vmss000000 Ready agent 22m v1.27.7
aks-default-34060743-vmss000001 Ready agent 22m v1.27.7 |
Application 배포 및 검증
사전 작업
애플리케이션 빌드 및 구성을 위해 먼저 JAVA, Maven 설치가 필요하다.
JAVA 설치
Code Block |
---|
# Install JDK
sudo apt update
sudo apt install default-jdk
# Verify the installation
java -version |
|
MAVEN 설치
Code Block |
---|
# Check the latest version
https://downloads.apache.org/maven/maven-3/
# Download Apache Maven
wget https://downloads.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz -P /tmp
# Extract the Archive
sudo tar xf /tmp/apache-maven-3.9.5-bin.tar.gz -C /opt
# Create a symbolic link
sudo ln -s /opt/apache-maven-3.9.5 /opt/maven
# Setup environment variables
sudo vi /etc/profile.d/maven.sh
export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
sudo chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh
# Verify the installation
mvn -version |
|
소스 준비 및 로컬 검증
먼저 샘플 소스를 내려 받는다.
Code Block |
---|
git clone https://github.com/zer0big/gs-spring-boot-aks.git
cd gs-spring-boot-aks
code . |
|
mvn clean package 명령으로 컴파일을 수행 한다. 참고로 clean 옵션은 maven build 시 생성된 모든 것들을 삭제한다.
Code Block |
---|
mvn clean package -DskipTests |
|
target 디렉토리로 이동 후 java -jar 명령을 통해 로컬에서 샘플 소스의 컴파일 결과를 실행하고 브라우저를 통해 유효성을 검증한다.
Code Block |
---|
java -jar gs-spring-boot-docker-0.1.0.jar |
|
Code Block |
---|
zerobig@winvm4azuresa:~/gs-spring-boot-aks/target$ java -jar gs-spring-boot-docker-0.1.0.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)
2022-07-17 17:56:30.666 INFO 7189 --- [ main] hello.Application : Starting Application v0.1.0 on winvm4azuresa with PID 7189 (/home/zerobig/gs-spring-boot-aks/target/gs-spring-boot-docker-0.1.0.jar started by zerobig in /home/zerobig/gs-spring-boot-aks/target)
2022-07-17 17:56:30.669 INFO 7189 --- [ main] hello.Application : No active profile set, falling back to default profiles: default
2022-07-17 17:56:32.043 INFO 7189 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-07-17 17:56:32.062 INFO 7189 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-07-17 17:56:32.063 INFO 7189 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2022-07-17 17:56:32.161 INFO 7189 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-07-17 17:56:32.161 INFO 7189 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1406 ms
2022-07-17 17:56:32.440 INFO 7189 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-07-17 17:56:32.657 INFO 7189 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-07-17 17:56:32.683 INFO 7189 --- [ main] hello.Application : Started Application in 3.058 seconds (JVM running for 3.798)
2022-07-17 17:57:39.998 INFO 7189 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-07-17 17:57:40.000 INFO 7189 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-07-17 17:57:40.020 INFO 7189 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 20 ms |
|
별도의 Windows 터미널 창에서 다음 명령을 수행한다.
Code Block |
---|
start http://localhost:8080 |
|
...
검증 완료 후 Ctrl + c를 실행하여 실행을 중지한다.
다음 작업 진행에 앞서 Bash 터미널 창에서 현재 target 디렉토리에서 상위 디렉토리로 이동한다.
Containerizing 및 로컬 검증
docker build 명령을 수행하여 docker images를 생성한다.
Code Block |
---|
docker build -t appmod-demo4tdgcms .
docker images |
|
Code Block |
---|
zerobig@sa-winvm:/mnt/c/Users/zerobig/gs-spring-boot-aks$ docker build -t appmod-demo4tdgcms .
[+] Building 10.0s (7/7) FINISHED docker:default
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.2s
=> => transferring dockerfile: 163B 0.0s
=> [internal] load metadata for docker.io/library/openjdk:8-jdk-alpine 2.8s
=> [internal] load build context 1.0s
=> => transferring context: 16.47MB 0.9s
=> [1/2] FROM docker.io/library/openjdk:8-jdk-alpine@sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3 5.3s
=> => resolve docker.io/library/openjdk:8-jdk-alpine@sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3 0.1s
=> => sha256:c2274a1a0e2786ee9101b08f76111f9ab8019e368dce1e325d3c284a0ca33397 70.73MB / 70.73MB 3.4s
=> => sha256:94792824df2df33402f201713f932b58cb9de94a0cd524164a0f2283343547b3 1.64kB / 1.64kB 0.0s
=> => sha256:44b3cea369c947527e266275cee85c71a81f20fc5076f6ebb5a13f19015dce71 947B / 947B 0.0s
=> => sha256:a3562aa0b991a80cfe8172847c8be6dbf6e46340b759c2b782f8b8be45342717 3.40kB / 3.40kB 0.0s
=> => sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10 2.76MB / 2.76MB 0.6s
=> => sha256:f910a506b6cb1dbec766725d70356f695ae2bf2bea6224dbe8c7c6ad4f3664a2 238B / 238B 0.3s
=> => extracting sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10 0.4s
=> => extracting sha256:f910a506b6cb1dbec766725d70356f695ae2bf2bea6224dbe8c7c6ad4f3664a2 0.0s
=> => extracting sha256:c2274a1a0e2786ee9101b08f76111f9ab8019e368dce1e325d3c284a0ca33397 1.4s
=> [2/2] ADD target/*.jar app.jar 1.5s
=> exporting to image 0.2s
=> => exporting layers 0.1s
=> => writing image sha256:e961dcb75ee02609f3339978200c57b972328ccc39d50fcd497233d2bdda8ef4 0.0s
=> => naming to docker.io/library/appmod-demo4tdgcms 0.0s
What's Next?
View a summary of image vulnerabilities and recommendations → docker scout quickview
zerobig@sa-winvm:/mnt/c/Users/zerobig/gs-spring-boot-aks$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
appmod-demo4tdgcms latest e961dcb75ee0 10 seconds ago 121MB |
|
docker run 명령을 수행하여 로컬에서 동작 유효성을 검증한다. 로컬포트는 임의로 지정 가능하다. 다음 예에서는 8888을 사용한다.
Code Block |
---|
zerobig@sa-winvm:/mnt/c/Users/zerobig/gs-spring-boot-aks$ docker run -d -p 8888:8080 appmod-demo4tdgcms
408c86d81b75b823858263d8f9b79a6d4ddf06d5ca6b63e04e0fa0ba431bb10a |
|
별도의 Windows 터미널 창에서 다음 명령을 수행한다.
Code Block |
---|
start http://localhost:8888 |
|
...
Docker Tag, Push
먼저 $ACR_Name 변수값을 확인하고 값이 없으면 등록 한다.
자신의 ACR 서버 주소 형식에 맞게 docker tag하고 push 명령을 수행하여 생성한 ACR에 images를 Push한다.
Code Block |
---|
docker tag appmod-demo4btc $ACR_NAME.azurecr.io/appmod-demo4tdgcms //자신의 ACR 서버 주소로 변경
docker images
az acr login -n $ACR_Name
docker push $ACR_NAME.azurecr.io/appmod-demo4btc |
|
Code Block |
---|
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ docker tag appmod-demo4tdgcms $ACR_Name.azurecr.io/appmod-demo4tdccms
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tdgzeroacrdemo.azurecr.io/appmod-demo4tdccms latest e961dcb75ee0 5 minutes ago 121MB
appmod-demo4tdgcms latest e961dcb75ee0 5 minutes ago 121MB
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ az acr login -n $ACR_Name
Login Succeeded
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ docker push $ACR_Name.azurecr.io/appmod-demo4tdccms
Using default tag: latest
The push refers to repository [tdgzeroacrdemo.azurecr.io/appmod-demo4tdccms]
5233ef201184: Pushed
ceaf9e1ebef5: Pushed
9b9b7f3d56a0: Pushed
f1b5933fe4b5: Pushed
latest: digest: sha256:3416501ad3533850c38167ade4cda018f5f1d878bb2713b2871884f835181d12 size: 1159
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ |
|
Azure Portal에서 등록 결과를 확인한다.
...
YAML Manifest 구성
k8s/deploy-svc.yaml 파일을 열어 “images” 정보를 각자의 값으로 업데이트 한다.
Code Block |
---|
apiVersion: apps/v1
kind: Deployment
metadata:
name: zeroaksdemo
spec:
replicas: 2
selector:
matchLabels:
app: zero-aks-app
template:
metadata:
labels:
app: zero-aks-app
spec:
containers:
- name: zero-aks-demo
image: tdgzeroacrdemo.azurecr.io/appmod-demo4tdccms:latest
|
|
8629e2fcf9724daysago121MBzeroacrdemo.azurecr.io/ap - containerPort: 8080
---
|
|
latestapiVersion: v1
kind: Service
|
|
8629e2fcf972 4 days ago121MB
zeroacrdemo.azurecr.io/appmod-contapp latest name: zero-aks-app
spec:
ports:
|
|
8629e2fcf9724 days ago121MBzeroacrtf.azurecr.io/appmod-contapplatest8629e2fcf9724daysago121MBPSC\Users\zerobig> docker tag appmod-contapp osd2023zeroacrdemo.azurecr.io/appmod-contapp:latest
PS C:\Users\zerobig> az acr login -n osd2023zeroacrdemo
Login Succeeded
PS C:\Users\zerobig> docker push osd2023zeroacrdemo.azurecr.io/appmod-contapp:latest
The push refers to repository [osd2023zeroacrdemo.azurecr.io/appmod-contapp]
7374f8b571a9: Pushed
ceaf9e1ebef5: Pushed
9b9b7f3d56a0: Pushed
f1b5933fe4b5: Pushed
latest: digest: sha256:ddf9994cb1630255c2fcec8b60617811ca751e59aaf7bcc99677028cd43f78c1 size: 1159
PS C:\Users\zerobig>YAML Manifest 구성
Code Block |
---|
apiVersion: apps/v1
kind: Deployment
metadata:
name: zeroaksdemo
spec:
replicas: 2
selector:
matchLabels:
app: zero-aks-app
template:
metadata:
labels:
app: zero-aks-app
spec:
containers:
zero-aks-app
type: LoadBalancer |
|
YAML Manifest 배포 및 결과 검증
Code Block |
---|
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-default-34060743-vmss000000 Ready agent 54m v1.27.7
aks-default-34060743-vmss000001 Ready agent 54m v1.27.7
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ kubectl apply -f k8s/deploy-svc.yaml
deployment.apps/zeroaksdemo created
service/zero-aks-app created
zerobig@sa-winvm:/mnt/c/Users/zerobig/TerroformAksDeployDemo$ kubectl get pod
NAME |
|
-name:zero-aks-demoimage:zeroacrtf.azurecr.io/web:latestports: RESTARTS AGE
zeroaksdemo-5686444c7c-29x5m 1/1 |
|
-containerPort:8080---apiVersion:v1kind:Servicemetadata:name:zeroaksappspec:ports:-name:http-portport:80 10s
zeroaksdemo-5686444c7c-mfb65 1/1 |
|
targetPort:8080selector: app: zero-aks-app
type: LoadBalancerYAML Manifest 배포 및 결과 검증
Code Block |
---|
zerobig@ZEROBIG-NT800:/mnt/d/2023_Azure/HandsOn/Terraform$ kubectl apply -f contapp-deploy-svc.yaml
deployment.apps/zeroaksdemo created
service/zero-aks-app created
zerobig@ZEROBIG-NT8000 10s
zerobig@sa-winvm:/mnt/dc/2023_AzureUsers/HandsOnzerobig/Terraform$TerroformAksDeployDemo$ kubectl get svc
podNAME --watch NAME TYPE CLUSTER-IP EXTERNAL-IP READY PORT(S) STATUS RESTARTS AGE
zeroaksdemo-5874694c78-2k6zkkubernetes 1/1 ClusterIP Running 10.0.0.1 <none> 7s zeroaksdemo-5874694c78-4xrbt 1/1 443/TCP 56m
zero-aks-app RunningLoadBalancer 10.0.50.60 20.196.252.253 80:32045/TCP 18s
7s
^Czerobig@ZEROBIGzerobig@sa-NT800winvm:/mnt/dc/2023_AzureUsers/HandsOnzerobig/Terraform$TerroformAksDeployDemo$ kubectl get svcpod
NAME TYPE CLUSTER-IP READY STATUS EXTERNAL-IP RESTARTS PORT(S) AGE
zeroaksdemo-5686444c7c-29x5m 1/1 AGE kubernetes Running 0 ClusterIP 10.0.0.1 68s
zeroaksdemo-5686444c7c-f2z85 <none>1/1 Running 0 443/TCP 17m68s
zerozeroaksdemo-aks-app5686444c7c-mfb65 1/1 LoadBalancerRunning 10.0.104.234 20.214.218.34 80:30193/TCP 3m2s zerobig@ZEROBIG-NT800:/mnt/d/2023_Azure/HandsOn/Terraform$ 68s |
|
Image Added