adx-web-basic-service
deployment yaml文件:
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: adx-web-basic-service
namespace: kube-ad
spec:
replicas: 1
template:
metadata:
labels:
app: adx-web-basic-service-app
spec:
containers:
- name: adx-web-basic-service-container
image: ad/ad-web-basic-service:1.0.3.0.25
env: # 环境变量
- name: CONSUL_CLIENT
value: 192.168.xx.xxx
- name: CONSUL_PORT
value: 8500
- name: SERVICE_PORT
value: 8777
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
livenessProbe:
httpGet:
path: /health/check/test # url后面的路径,不包括ip和端口,会自动检测对应pod
port: 8777
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
volumeMounts:
- mountPath: /app/newgetui/adx-web-basic/resource # 容器内挂载路径
name: app-resource
- mountPath: /app/newgetui/adx-web-basic/current/logs
name: logs
volumes:
- name: app-resource
hostPath:
path: /app/newgetui/adx-web-basic/resource # 物理机挂载路径
- name: logs
hostPath:
path: /app/newgetui/adx-web-basic/logs
nodeSelector:
schedulable: "true"
这样创建deployment,k8s自己会根据调度策略,将pod放在某个node上;不过我们可以在deployment.yaml中设置指定的node;使用nodeSelector,如上
service yaml文件:
---
apiVersion: v1
kind: Service
metadata:
labels:
name: adx-web-basic-service
name: adx-web-basic-service
namespace: kube-td
spec:
type: NodePort
ports:
- port: 8777
targetPort: 8777
nodePort: 8777
name: adx-web-basic-service-8777
selector:
app: adx-web-basic-service-app
端口说明:
service.yaml中定义的port(80), tartget port(8081), nodePort(32143)这三个端口是什么关系呢,这里有点绕,先看下图:
注意上图里面的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端口号,也是容器内具体服务的端口号