드디어 돌아왔다 3티어 아키텍쳐...
실습
쿠버네티스 클러스터 내에서 3계층 아키텍쳐 구성
1. mysql 이미지를 이용해서 DB생성
2. was 서버는 tomcat:9.0
3. web 서버는 httpd:2.4
4. 각서버는 이중화 안함
모두 node1에 폴더를 구성하였다
mysql /3tir/mysql
web /3tir/web
was /3tir/was
mysql.yml
#mysql 시크릿 파일생성
apiVersion: v1
kind: Secret
metadata:
name: mysql-sec
data:
MYSQL_ROOT_PASSWORD: cXdlcjEyMzQ= #qwer1234 를 base64 인코딩한값
---
#PV생성 (mysql)
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 10G #용량2기가
accessModes:
- ReadWriteOnce
local: #지금은 로컬에 연결 각종타입이 지원됨
path: /3tir/mysql #디렉토리를 생성해둬야함
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [node1]}
---
#PVC 로 PV연동
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10G
storageClassName: ""
---
apiVersion: v1
kind: Pod
metadata:
name: mysql-server
labels:
app: db-pod
spec:
nodeSelecter:
kubernetes.io/hostname: node1
containers:
- name: mysql
image: mysql
ports:
- containerPort: 3306
envFrom:
- secretRef:
name: mysql-sec #mysql 설정파일을 불러오자
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-pvc-pv
volumes:
- name : mysql-pvc-pv
persistentVolumeClaim:
claimName: mysql-pvc
---
#mysql 서비스 생성
apiVersion: v1
kind: Service
metadata:
name: svc-mysql
spec:
selector:
app: db-pod
ports:
- port: 3306
containerPort: 3306
============================= WAS 서버 =================================
Dockerfile
FROM tomcat:9.0
RUN rm -rf /usr/local/tomcat/conf/server.xml
ADD ./server.xml /usr/local/tomcat/conf/server.xml
8EXPOSE 8080
EXPOSE 8009
CMD catalina.sh run
docker build --tag yoskr/yos_tomcat:0.7 .
was.yml
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-was
spec:
capacity:
storage: 2G #용량2기가
accessModes:
- ReadWriteOnce
local: #지금은 로컬에 연결 각종타입이 지원됨
path: /3tir/was #디렉토리를 생성해둬야함
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [node1]}
---
#PVC 로 PV연동
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-was
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2G
storageClassName: ""
---
#파드
apiVersion: v1
kind: Pod
metadata:
name: was-server
labels:
app: pod-was
spec:
nodeSelecter:
kubernetes.io/hostname: node1
containers:
- name: was
image: yoskr/yos_tomcat:1.1
ports:
- containerPort: 8009
volumeMounts:
- mountPath: /usr/local/tomcat/webapps
name: was-pvc-pv
volumes:
- name : was-pvc-pv
persistentVolumeClaim:
claimName: pvc-was
#was 서비스 생성 - 클러스터 형식으로
apiVersion: v1
kind: Service
metadata:
name: tomcat-svc
spec:
selector:
app: pod-was
ports:
- name: live
port: 8009
containerPort: 8009
- name: test
port: 8080
containerPort: 8080
#테스트후 test port 끄자
================== WEB서버=========================
Dockerfile
FROM httpd:2.4
RUN apt update
RUN apt install -y libapache2-mod-jk # buildkit
RUN cp /usr/lib/apache2/modules/mod_jk.so /usr/local/apache2/modules/mod_jk.so # mod_jk.so 찾아서 복사하기
RUN sed -i 's/localhost/tomcat-svc/g' /etc/libapache2-mod-jk/workers.properties # localhost 를 tomcat-svc로 가게 바꾸기
RUN rm -rf /usr/local/apache2/conf/httpd.conf #httpd.conf 삭제
ADD ./httpd.conf /usr/local/apache2/conf/httpd.conf #httpd.conf 추가
EXPOSE 80
CMD httpd-foreground
httpd.conf 추가본으로 만들기
LoadModule jk_module modules/mod_jk.so
<IfModule jk_module>
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkLogFile /usr/local/apache2/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkMount /*.jsp ajp13_worker
JkShmFile /usr/local/apache2/logs/jk-runtime-status
</IfModule>
web.yml
#PV생성 (web)
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-web
spec:
capacity:
storage: 2G #용량2기가
accessModes:
- ReadWriteOnce
local: #지금은 로컬에 연결 각종타입이 지원됨
path: /3tir/web
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [node1]}
---
#PVC 로 PV연동
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-web
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2G
storageClassName: ""
---
#web 파드(도커에서 만들어서 와야할듯?)
apiVersion: v1
kind: Pod
metadata:
name: web-server
labels:
app: pod-web
spec:
nodeSelecter:
kubernetes.io/hostname: node1
containers:
- name: web
image: yoskr/httpd:0.1
ports:
- containerPort: 80
volumeMounts:
- mountPath: /usr/local/apache2/htdocs
name: web-pvc-pv
volumes:
- name : web-pvc-pv
persistentVolumeClaim:
claimName: pvc-web
---
#web 서비스 생성 - 클러스터 형식으로
apiVersion: v1
kind: Service
metadata:
name: svc-web
spec:
selector:
app: pod-web
ports:
- port: 80 # 사용자들이 접속할 포트
targetPort: 80 # 파드의 포트번호
type: LoadBalancer
도커 빌드시 하두 하면 가끔 apt update가 안된다 그럴땐 노캐쉬 써주면되더라
docker build --no-cache -tag [파일명]
추후 수정할사항
이방식은 빠르게 구성한것이고 원래는 설정파일을 삭제하지 않고 불러오는 방식으로 구현해야 한다.
728x90
반응형