测试环境 需要启动jacoco 并暴露端口 replicas为1 但是node为2个 没有指定pod在哪个节点上启动。因此打算用nodeport的方式暴露出来,这样认准一个node+nodeport就可以跑jacoco了
haozhuo-health-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
# deployment名字 和svc 和ingress绑定没关系
name: haozhuo-health-dp
namespace: test
spec:
replicas: 1
# 在定义模板的时候必须定义labels,因为Deployment.spec.selector是必须字段,而他又必须和template.labels对应
selector:
matchLabels:
app: haozhuo-health
# template里面定义的内容会应用到下面所有的副本集里面(例如depolyment下的pod),在template.spec.containers里面不能定义labels标签。可以kubectl get pods --show-labels查看
template:
metadata:
labels:
app: haozhuo-health
env: test
spec:
containers:
# containers名字 和svc 和ingress绑定没关系
- name: haozhuo-health
image: registry.cn-shanghai.aliyuncs.com/yjk-datag/k8s-haozhuo-health:v19
#image: registry.cn-shanghai.aliyuncs.com/yjk-datag/haozhuo-video:vtest06
env:
- name: DUBBO_IP_TO_REGISTRY
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: DUBBO_PORT_TO_REGISTRY
value: "20909"
resources:
limits:
cpu: 2000m
memory: 2048Mi
requests:
cpu: 1000m
memory: 1024Mi
ports:
- name: jacoco-port
containerPort: 6309
- name: liveness-port
containerPort: 8080
# 使用了 hostPort 的容器只能调度到端口不冲突的 Node 上,除非有必要(比如运行一些系统级的 daemon 服务),不建议使用端口映射功能。
# 跟 hostPort 一样的原因,避免使用 hostNetwork。
# hostPorts:
# - min: 8000
# max: 8080
hostPort: 8809
- name: readiness-port
containerPort: 20909
hostPort: 20909
# 后续需要jacoco端口也暴露一下
livenessProbe:
tcpSocket:
port: liveness-port
initialDelaySeconds: 20
periodSeconds: 3
readinessProbe:
tcpSocket:
port: readiness-port
initialDelaySeconds: 30
periodSeconds: 10
imagePullSecrets:
- name: aliyun-ns-test
# 创建statefulset
kubectl apply -f haozhuo-health-deployment.yaml
haozhuo-health-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: haozhuo-health-service
namespace: test
spec:
type: NodePort
ports:
- name: tcp
port: 6309
nodePort: 30309
selector:
app: haozhuo-health
# 创建svc
kubectl apply -f haozhuo-health-svc.yaml
jenkins 结果