kubernetes微服务部署

时间:2023-01-29 15:07:40
1.哪些服务适合单独成为一个pod?哪些服务适合在一个pod中?
message消息服务被很多服务调用   单独一个pod
dubbo服务和web服务交互很高放在同一个pod里
API网关调用很多服务  单独一个pod
 
2.在一个pod里面的服务如何彼此访问?他们的服务如何对外提供服务?
dubbo服务和web服务(在一个pod里)通过本机IP+端口访问
通过service里的clusterip和dns   服务在集群内部访问
 
course-service.yml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: course-service
  name: course-service
spec:
  ports:
  - port: 8081
    protocol: TCP
    targetPort: 8081
  selector:
    app: course-service
  type: ClusterIP
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: course-service-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: course-service
    spec:
      containers:
      - name: course-service
        image: {{HUB}}/micro-service/course-service:latest
        ports:
        - containerPort: 20880
      - name: course-edge-service
        image: {{HUB}}/micro-service/course-edge-service:latest
        ports:
        - containerPort: 8081
 
 
3.单独的pod如何对外提供服务?
 
message-service.yml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: message-service
  name: message-service
spec:
  ports:
  - port: 9090
    protocol: TCP
    targetPort: 9090
  selector:
    app: message-service
  type: ClusterIP
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: message-service-deployment
spec:
  replicas: 1
  template: 
    metadata:
      labels:
        app: message-service
    spec:
      containers:
      - name: message-service
        image: {{HUB}}/micro-service/message-service:latest
        ports:
        - containerPort: 9090
 
4.哪个服务作为整个服务的入口,入口服务如何对外提供服务?
通过nodepod,集群外就可以访问这个服务
 
apigateway.yml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: api-gateway
  name: api-gateway
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
    nodePort: 80
  selector:
    app: api-gateway
  type: NodePort
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: api-gateway-deployment
spec:
  replicas: 1
  template: 
    metadata:
      labels:
        app: api-gateway
    spec:
      containers:
      - name: api-gateway
        image: {{HUB}}/micro-service/api-gateway-zuul:latest
        ports:
        - containerPort: 8080