이번엔 로그인 기능에서 사용하는 토큰을 올리기 위해 redis를 올려보고자 한다.
1. Local
/application.properties
spring.redis.host=127.0.0.1 spring.redis.port=6379
이걸 추가한다.
/local/docker-compose.yml
version: "3"
services:
mysql:
image: mysql:5.6
environment:
MYSQL_DATABASE: bizschema
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_USER: devroot
MYSQL_PASSWORD: devpw
LANG: C.UTF-8
volumes:
- local-mysqlvol:/var/lib/mysql
ports:
- 3306:3306
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
container_name: local-mysql
redis:
image: redis:alpine
hostname: redis-local
ports:
- 6379:6379
container_name: local-redis
volumes:
local-mysqlvol:
항상 그랬듯 redis 이미지를 당겨온다.
2. CI Server
ci server에서도 마찬가지다. 다만 spring과 연동이 되어야 하므로 network를 추가하자.
/ci-server/docker-compose.yml
version: "3"
services:
jenkins:
container_name: jenkins-compose
image: jenkins/jenkins:lts
user: root
ports:
- "8081:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- jenkins_data:/var/jenkins_home
networks:
- backend-network
sonarqube:
image: sonarqube:lts
container_name: sonarqube
ports:
- "9000:9000"
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
mysql:
image: mysql:5.6
container_name: ci-mysql
environment:
MYSQL_DATABASE: bizschema
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_USER: devroot
MYSQL_PASSWORD: devpw
LANG: C.UTF-8
ports:
- "3306:3306"
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
volumes:
- ciserver-mysqlvol:/var/lib/mysql
networks:
- backend-network
redis:
image: redis:alpine
hostname: redis-local
ports:
- 6379:6379
container_name: local-redis
networks:
- backend-network
volumes:
ciserver-do:
jenkins_data:
sonarqube_conf:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
networks:
backend-network:
3. Deploy Server
/deploy/redis.yml
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: redis
spec:
type: LoadBalancer
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:alpine
ports:
- containerPort: 6379
env:
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
#- name: REDIS_PASSWORD
# value: your-password
만약 redis 비밀번호를 쓰고 싶으면 위에서 주석처리 되어 있는 redis_password를 설정해주면 된다. 이후 이걸 apply해서 redis의 service port를 받아온다.
/deploy/spring.yml
apiVersion: apps/v1
kind: Deployment
metadata: # deployment의 metadata
name: spring-board-deploy
spec: # deployment의 spec
replicas: 1
selector:
matchLabels:
app: spring
tier: backend
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 2
template: # 다음 줄부터는 각각 pod의 설정
metadata:
labels: # 각 pod들의 metadata
app: spring
tier: backend
spec: # pod의 spec
containers:
- name: echo
image: gcr.io/temporal-fx-321902/bizkicks-backend:0.0.6.2
ports: #
- containerPort: 8080
env:
- name: SPRING_DATASOURCE_USERNAME
valueFrom:
secretKeyRef:
name: userinfo
key: username
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: userinfo
key: userpw
- name: SPRING_DATASOURCE_URL
valueFrom:
secretKeyRef:
name: dbinfo
key: url
- name: SPRING_REDIS_HOST
valueFrom:
secretKeyRef:
name: reidsinfo
key: host
- name : SPRING_REDIS_PORT
valueFrom:
secretKeyRef:
name: reidsinfo
key: port
---
apiVersion: v1
kind: Service
metadata: # Service의 metadata
name: spring-board-service
spec:
type: LoadBalancer
ports:
- port: 8080 # Service가 생성할 Port
targetPort: 8080 # Service가 접근할 pod의 port
selector: # Service가 접근할 pod의 label 조건
app: spring
tier: backend
SPRING_REDIS_PORT, SPRING_REDIS_HOST 2개에 값을 채워넣으면 완성!