实战: mysql 单独部署在集群外部250节点。
然后K8s 集群内部的tomcat 可是访问 250
项目路径:
01-ep-mysql57.yaml
apiVersion: v1
kind: Endpoints
metadata:
name: baimei-mysql-ep
subsets:
- addresses:
- ip: 10.0.0.250
# 配置端口
ports:
- port: 3306
name: mysql-ep
02-svc-mysql57.yaml
apiVersion: v1
kind: Service
metadata:
name: baimei-mysql-ep
spec:
type: ClusterIP
ports:
- port: 3306
name: mysql-ep
03-deploy-tomcat.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: baimei-tomcat-app
spec:
replicas: 1
selector:
matchExpressions:
- key: app
operator: Exists
template:
metadata:
labels:
app: baimei-tomcat-app
spec:
containers:
- name: tomcat
image: harbor.baimei.com/baimei-tomcat/tomcat-app:v1
ports:
- containerPort: 8080
env:
- name: MYSQL_SERVICE_HOST
value: baimei-mysql-ep
- name: MYSQL_SERVICE_PORT
value: '3306'
04-svc-tomcat.yaml
apiVersion: v1
kind: Service
metadata:
name: baimei-tomcat-app
spec:
type: NodePort
selector:
app: baimei-tomcat-app
ports:
- port: 8080
targetPort: 8080
nodePort: 8080
欢迎来撩 : 汇总all