도커 컨테이너 확인
WEB/WAS/DB 컨테이너 실행 명령어
docker run -itd --name apache -p 80:80 httpd
docker run -itd --name tomcat -p 8080:8080 tomcat
docker run -itd --name mysql -e MYSQL_ROOT_PASSWORD=It1 -e \
MYSQL_DATABASE=jininfra -e MYSQL_USER=jininfra -e MYSQL_PASSWORD=It1 mysql
WEB-WAS → mod_proxy 연동, WAS-DB → Connector 설치 후 연동, 연동시 각각의 IP는 docker inspect 명령어로 나온 내부 IP로 연동
WEB-WAS 연동 확인
WAS-DB 연동 확인
DB 연동 테스트 JSP
<%@ page import="java.sql.*" contentType="text/html;charset=utf-8"%>
<%
String DB_URL = "jdbc:mysql://172.17.0.4:3306/jininfra";
String DB_USER = "root";
String DB_PASSWORD= "It1";
ResultSet rs = null;
Connection conn;
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
stmt = conn.createStatement();
conn.close();
out.println("MySQL Connection Success!");
/*
rs = stmt.executeQuery("테스트 쿼리");
while(rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getString("test1") + "</td>");
out.println("<td>" + rs.getString("test2") + "</td>");
out.println("</tr>");
}
*/
}
catch(Exception e){
out.println(e);
}
%>
WEB/WAS/DB 이미지 도커 커밋, 푸시 후 확인
1. 3티어 쿠버네티스 적용(WEB-WAS 연동)
우선 구성은 External LB - WEB (1ea) - Internal LB - WAS(3ea) - DB
서비스 이름 web이 External, internal-lb가 internal
외부 IP 유/무로 확인 가능
External LB 생성 명령어
kubectl expose deployment web --port=80 --target-port=80 --type=LoadBalancer
Internal LB 생성 yaml (외부 IP가 없는 Cluster IP 형태, selector로 붙힐 was 설정)
apiVersion: v1
kind: Service
metadata:
name: internal-lb
spec:
type: ClusterIP
ports:
- name: was
port: 8080
targetPort: 8080
selector:
app: 3tier
도커에서 이미지 수정 필요. WEB에서 mod_proxy 연결 IP를 Internal LB 클러스터 IP로 지정함.
pod 만들때 가장 최신 이미지로 apply 하였음.
톰캣에서는 현재 서버의 IP를 확인하는 ip.jsp 작성
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>IP Address</title>
</head>
<body>
<h1>Server IP Address: <%= request.getLocalAddr() %></h1>
</body>
</html>
도커 이미지 커밋, 푸시 후 쿠버네티스 WEB, WAS deployment apply
kubectl apply -f **.yaml
## WEB.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: 3tier
spec:
replicas: 1
selector:
matchLabels:
app: 3tier
template:
metadata:
labels:
app: 3tier
spec:
containers:
- name: lsy-web
image: df37f1bc-kr2-registry.container.nhncloud.com/lsy-ncr/lsy-apache:0.4
ports:
- containerPort: 80
imagePullSecrets:
- name: regcred
## WAS.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: was
labels:
app: 3tier
spec:
replicas: 3
selector:
matchLabels:
app: 3tier
template:
metadata:
labels:
app: 3tier
spec:
containers:
- name: lsy-was
image: df37f1bc-kr2-registry.container.nhncloud.com/lsy-ncr/lsy-tomcat:0.2
ports:
- containerPort: 8080
imagePullSecrets:
- name: regcred
WEB-WAS 연동 결과
133.186.201.94는 External LB의 FIP
로드 밸런싱 확인을 위해, WAS pod 클러스터 IP 확인 및 접속 하여 IP로 로드밸런싱 확인
2. 3티어 쿠버네티스 적용(WAS-DB 연동)
DB Pod 생성 및 IP 확인
apiVersion: v1
kind: Pod
metadata:
name: db
labels:
app: 3tier
spec:
containers:
- name: lsy-db
image: df37f1bc-kr2-registry.container.nhncloud.com/lsy-ncr/lsy-mysql:0.1
ports:
- containerPort: 3306
imagePullSecrets:
- name: regcred
WAS에 있는 dbtest.jsp에 DB 연결 URL을 아래 빨간 박스 친 클러스터 IP로 변경
도커 이미지 커밋, 푸시
WAS yaml파일 이미지 변경 및 pod 재생성
##WAS.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: was
labels:
app: 3tier
spec:
replicas: 3
selector:
matchLabels:
app: 3tier
template:
metadata:
labels:
app: 3tier
spec:
containers:
- name: lsy-was
image: df37f1bc-kr2-registry.container.nhncloud.com/lsy-ncr/lsy-tomcat:0.3
ports:
- containerPort: 8080
imagePullSecrets:
- name: regcred
pod 생성 후 dbtest.jsp 호출 및 db 연동 확인
결론 : WEB-WAS-DB 쿠버네티스 pod로 연동 확인
정리 :
WEB→deployment(replica:1)
WAS→deployment(replica:3)
DB→pod
External LB 1ea (외부 IP 사용), Internal LB 1ea (클러스터 IP 사용)
WEB-WAS-DB 연동 확인
이미지 업데이트할때마다 해야할일 多, CI/CD 구성 필요
'IT > Kubernetes' 카테고리의 다른 글
K8S_wordpress 설치하기 (0) | 2022.08.10 |
---|---|
K8S_deployment (0) | 2022.08.10 |
K8S_Service-NodePort, ReplicaSet (0) | 2022.08.09 |
K8S_label, mysql 설치 (0) | 2022.08.04 |
K8S_cp, expose, namespace 연습 (0) | 2022.08.04 |