adx-web-basic-service

deployment yaml文件:

  1. ---
  2. apiVersion: extensions/v1beta1
  3. kind: Deployment
  4. metadata:
  5. name: adx-web-basic-service
  6. namespace: kube-ad
  7. spec:
  8. replicas: 1
  9. template:
  10. metadata:
  11. labels:
  12. app: adx-web-basic-service-app
  13. spec:
  14. containers:
  15. - name: adx-web-basic-service-container
  16. image: ad/ad-web-basic-service:1.0.3.0.25
  17. env: # 环境变量
  18. - name: CONSUL_CLIENT
  19. value: 192.168.xx.xxx
  20. - name: CONSUL_PORT
  21. value: 8500
  22. - name: SERVICE_PORT
  23. value: 8777
  24. - name: NAMESPACE
  25. valueFrom:
  26. fieldRef:
  27. fieldPath: metadata.namespace
  28. livenessProbe:
  29. httpGet:
  30. path: /health/check/test # url后面的路径,不包括ip和端口,会自动检测对应pod
  31. port: 8777
  32. scheme: HTTP
  33. initialDelaySeconds: 60
  34. timeoutSeconds: 5
  35. volumeMounts:
  36. - mountPath: /app/newgetui/adx-web-basic/resource # 容器内挂载路径
  37. name: app-resource
  38. - mountPath: /app/newgetui/adx-web-basic/current/logs
  39. name: logs
  40. volumes:
  41. - name: app-resource
  42. hostPath:
  43. path: /app/newgetui/adx-web-basic/resource # 物理机挂载路径
  44. - name: logs
  45. hostPath:
  46. path: /app/newgetui/adx-web-basic/logs
  47. nodeSelector:
  48. schedulable: "true"

这样创建deployment,k8s自己会根据调度策略,将pod放在某个node上;不过我们可以在deployment.yaml中设置指定的node;使用nodeSelector,如上


service yaml文件:

  1. ---
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. labels:
  6. name: adx-web-basic-service
  7. name: adx-web-basic-service
  8. namespace: kube-td
  9. spec:
  10. type: NodePort
  11. ports:
  12. - port: 8777
  13. targetPort: 8777
  14. nodePort: 8777
  15. name: adx-web-basic-service-8777
  16. selector:
  17. app: adx-web-basic-service-app

端口说明:
service.yaml中定义的port(80), tartget port(8081), nodePort(32143)这三个端口是什么关系呢,这里有点绕,先看下图:
image.png
注意上图里面的IP和端口和笔者用的端口不一致,但此图大致描述了上面三个端口之间的关系。首先外部使用load balancer访问我们的两个slave节点(192.168.29.141:32143) 和 (192.168.29.139:32143),接着它会访问Service,即ClusterIP(10.97.114.36:80), Service再通过load balancer访问到某一个pod(端口8081)里的container(端口8081)。 这里第二个load balancer是由kube-proxy来负责的,官方的描述是:kube-proxy负责为service提供cluster内部的服务发现和负载均衡;

  • port:service端口号
  • nodePort:node节点暴露给外部访问service的端口号
  • targetPort:pod端口号,也是容器内具体服务的端口号