51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

k8s endpoints tomcat实战案例

实战: 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

赞(9)
未经允许不得转载:工具盒子 » k8s endpoints tomcat实战案例