본문 바로가기

가상화/Kubernetes

[kubernetes] Kubernetes에서 Ingress 와 Tomcat 연동

반응형

개요

구성환경

 

1. Tomcat 이미지 다운로드

shell> docker pull tomcat:8.5.53

2. 배치 생성

shell> kubectl apply -f tomcatproject1-deployment.yaml

- tomcatproject1-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcatproject1-deployment
  labels:
    app: tomcatproject1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcatproject1
  template:
    metadata:
      labels:
        app: tomcatproject1
    spec:
      containers:
      - name: tomcatproject1
        image: tomcat:8.5.53
        env:
        - name: JAVA_OPTS
          value: "-Xms512m -Xmx512m"
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: projectvol1
          mountPath: /usr/local/tomcat/webapps
          readOnly: false
      volumes:
      - name : projectvol1
        hostPath:
          path: /var/lib/tomcat

3. 서비스 생성

shell> kubectl expose deploy tomcatproject1-deployment --type=LoadBalancer

4. ingress 작성

shell> kubectl apply -f ingress-sample.yaml

- ingress-sample.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hoya-com-tomcat-ingress
  annotations:
spec:
  rules:
  - host: www.hoya.com
    http:
      paths:
      - path: /
        backend:
          serviceName: tomcatproject1-deployment
          servicePort: 8080

5. 어플리케이션 배포

예시) apache-tomcat-8.5.54.tar.gz 파일의 webapps 디렉토리 아래의 examples 폴더를 로컬 파일시스템의 /var/lib/tomcat 폴더로 복사

shell> tar zxvf apache-tomcat-8.5.54.tar.gz
shell> cd apache-tomcat-8.5.54/
shell> cd webapps/
shell> cp -rP examples/ /var/lib/tomcat/

6. 테스트

shell> curl http://www.hoya.com/examples/ 

반응형