先安装Ingress Controller
安装Ingress Controller后,其他服务设置Ingress后就可以通过设置的域名进⾏访问了,就不⽤通过代理的⽅式或者ip:port的⽅式进⾏访问了
安装Ingress Controller
安装Ingress Controller后的效果
⼏种不同的访问⽅式
1.通过代理⽅式访问2.通过ip:port⽅式访问3.通过域名⽅式访问
因为是在本机进⾏的测试,需要在本机hosts中添加解析
192.168.75.11 cloud-eureka.hkd.demo.kuboard.cn
改造项⽬使⽤的Dockerfile⽂件部署eureka
需要采⽤Statefulsets,不能采⽤Delpoyments
原因分析:
采⽤Delpoyments的话,设置三个副本,eureka界⾯上会显⽰三个出来但是会有问题,其他服务⽆法注册进来
采⽤Statefulsets的话,设置三个副本,eureka界⾯上会显⽰随机显⽰两个出来,刷新页⾯,会显⽰的这俩会随机变动,总之不会显⽰三个,并且其他服务也能注册进来步骤选项
部署config部署gateway部署auth
eureka,config,gateway,auth效果其他模块
剩余的其他模块配置差不多都⼀样,都是在StatefulSet,镜像tag是0.3,都开启了Service,但是没有开启ingress
最终效果
思考:关于模块要不要开启访问⽅式 Service?要不要开启ingress?1.Service是必须要开的
因为若关闭的话,有些服务是依赖于其他服务的,假若把config模块的给关了,则gateway模块会因为找不到config⽽⽆法启动关闭后的效果开启后的效果
2.ingress,这个根据情况⽽定,这个是给外⽹访问⽤的,有些模块需要进⾏外⽹访问,⽐如eureka,有些不需要,那么只给有需要的开启,没需要的就不开启
导出⼯作负载
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: cloud-config annotations:
k8s.kuboard.cn/workload: cloud-config k8s.kuboard.cn/displayName: 配置中⼼
k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-configspec: selector:
matchLabels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-config revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-config spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-config:0.3' imagePullPolicy: Always name: hkd-config volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
nodeName: worker
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: cloud-config
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: cloud-config annotations:
k8s.kuboard.cn/workload: cloud-config k8s.kuboard.cn/displayName: 配置中⼼ labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-configspec: selector:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-config type: NodePort ports:
- port: 8888
targetPort: 8888 protocol: TCP name: msbf6b nodePort: 30886
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: cloud-eureka annotations:
k8s.kuboard.cn/workload: cloud-eureka
k8s.kuboard.cn/displayName: 服务注册中⼼ k8s.kuboard.cn/ingress: 'true'
k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eurekaspec: selector:
matchLabels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-eureka:0.3' imagePullPolicy: Always
name: eureka-server volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 3
volumeClaimTemplates: [] serviceName: cloud-eureka
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: cloud-eureka annotations:
k8s.kuboard.cn/workload: cloud-eureka
k8s.kuboard.cn/displayName: 服务注册中⼼ labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eurekaspec: selector:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eureka type: NodePort ports:
- port: 8761
targetPort: 8761 protocol: TCP name: siwrzh nodePort: 30242
---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:
namespace: hkd name: cloud-eureka annotations:
k8s.kuboard.cn/workload: cloud-eureka
k8s.kuboard.cn/displayName: 服务注册中⼼ labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-eurekaspec: rules:
- host: cloud-eureka.hkd.demo.kuboard.cn http: paths: - path: / backend:
serviceName: cloud-eureka servicePort: siwrzh
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: gateway-gw2 annotations:
k8s.kuboard.cn/workload: gateway-gw2 k8s.kuboard.cn/displayName: ⽹关中⼼ k8s.kuboard.cn/ingress: 'true'
k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-gw2spec: selector:
matchLabels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-gw2 revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-gw2 spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-gateway:0.3' imagePullPolicy: Always name: hkd-gateway volumeMounts: [] resources: limits: requests:
env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: gateway-gw2
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: gateway-gw2 annotations:
k8s.kuboard.cn/workload: gateway-gw2 k8s.kuboard.cn/displayName: ⽹关中⼼ labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-gw2spec: selector:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-gw2 type: NodePort ports:
- port: 5000
targetPort: 5000 protocol: TCP name: m6ykbh nodePort: 31646
---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:
namespace: hkd name: gateway-gw2 annotations:
k8s.kuboard.cn/workload: gateway-gw2 k8s.kuboard.cn/displayName: ⽹关中⼼ labels:
k8s.kuboard.cn/layer: gateway
k8s.kuboard.cn/name: gateway-gw2spec: rules:
- host: gwateway-gw2.hkd.demo.kuboard.cn http: paths: - path: / backend:
serviceName: gateway-gw2 servicePort: m6ykbh
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: svc-auth annotations:
k8s.kuboard.cn/workload: svc-auth k8s.kuboard.cn/displayName: 验证中⼼ k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-authspec: selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-auth revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-auth spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-auth:0.3' imagePullPolicy: Always name: hkd-auth volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {}
volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: svc-auth
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: svc-auth annotations:
k8s.kuboard.cn/workload: svc-auth k8s.kuboard.cn/displayName: 验证中⼼ labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-authspec: selector:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-auth type: NodePort ports:
- port: 8765
targetPort: 8765 protocol: TCP name: wjn5hh nodePort: 32443
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: svc-cash annotations:
k8s.kuboard.cn/workload: svc-cash k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-cashspec: selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-cash revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-cash spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-cash:0.3' imagePullPolicy: Always name: hkd-cash volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: svc-cash
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: svc-cash annotations:
k8s.kuboard.cn/workload: svc-cash labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-cashspec: selector:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-cash type: NodePort ports:
- port: 8766
targetPort: 8766 protocol: TCP
name: kfcdez nodePort: 31091
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: svc-custom annotations:
k8s.kuboard.cn/workload: svc-custom k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-customspec: selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-custom revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-custom spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-custom:0.3' imagePullPolicy: Always name: hkd-custom volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: svc-custom
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: svc-custom annotations:
k8s.kuboard.cn/workload: svc-custom labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-customspec: selector:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-custom type: NodePort ports:
- port: 8764
targetPort: 8764 protocol: TCP name: e82zsm nodePort: 32733
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: svc-portal annotations:
k8s.kuboard.cn/workload: svc-portal k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-portalspec: selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-portal revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-portal spec:
securityContext:
seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-portal:0.3' imagePullPolicy: Always name: hkd-portal volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: svc-portal
---apiVersion: v1kind: Servicemetadata:
namespace: hkd name: svc-portal annotations:
k8s.kuboard.cn/workload: svc-portal labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-portalspec: selector:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-portal type: NodePort ports:
- port: 8767
targetPort: 8767 protocol: TCP name: sbwmf2 nodePort: 31346
---apiVersion: apps/v1kind: StatefulSetmetadata:
namespace: hkd name: svc-user annotations:
k8s.kuboard.cn/workload: svc-user k8s.kuboard.cn/displayName: ⽤户 k8s.kuboard.cn/ingress: 'false' k8s.kuboard.cn/service: NodePort labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-userspec: selector:
matchLabels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-user revisionHistoryLimit: 10 template: metadata: labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-user spec:
securityContext: seLinuxOptions: {} imagePullSecrets: - name: nexus
restartPolicy: Always initContainers: [] containers:
- image: 'idocker.io/hkd-user:0.3' imagePullPolicy: Always name: hkd-user volumeMounts: [] resources: limits: requests: env: [] envFrom:
- configMapRef:
name: eureka-config lifecycle: {} volumes: []
dnsPolicy: ClusterFirst dnsConfig: {}
terminationGracePeriodSeconds: 30 replicas: 1
volumeClaimTemplates: [] serviceName: svc-user---apiVersion: v1
kind: Servicemetadata:
namespace: hkd name: svc-user annotations:
k8s.kuboard.cn/workload: svc-user k8s.kuboard.cn/displayName: ⽤户 labels:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-userspec: selector:
k8s.kuboard.cn/layer: svc
k8s.kuboard.cn/name: svc-user type: NodePort ports:
- port: 8763
targetPort: 8763 protocol: TCP name: s5egas nodePort: 30083
---metadata:
name: eureka-config namespace: hkd managedFields: - manager: Mozilla operation: Update apiVersion: v1
time: '2020-06-29T01:44:36Z' fieldsType: FieldsV1 fieldsV1: 'f:data': .: {}
'f:eureka.client.serviceUrl.defaultZone': {} 'f:eureka.instance.prefer-ip-address': {}data:
eureka.client.serviceUrl.defaultZone: >- http://cloud-eureka-0.cloud-eureka.hkd.svc.cluster.local:8761/eureka,http://cloud-eureka-1.cloud-eureka.hkd.svc.cluster.local:8761/eureka,http://cloud-eureka-2.cloud-eureka.hkd.svc.cluster.local:8761/eureka eureka.instance.prefer-ip-address: 'false'kind: ConfigMapapiVersion: v1
---metadata: name: nexus namespace: hkd managedFields: - manager: Mozilla operation: Update apiVersion: v1
time: '2020-06-28T07:45:21Z' fieldsType: FieldsV1 fieldsV1: 'f:data': .: {}
'f:.dockerconfigjson': {} 'f:type': {}data:
.dockerconfigjson: >- eyJhdXRocyI6eyJodHRwczovL2lkb2NrZXIuaW8iOnsidXNlcm5hbWUiOiJhZG1pbiIsInBhc3N3b3JkIjoibmV3bm9kZTc4NTIiLCJhdXRoIjoiWVdSdGFXNDZibVYzYm05a1pUYzROVEk9In19fQ==type: kubernetes.io/dockerconfigjsonkind: SecretapiVersion: v1
因篇幅问题不能全部显示,请点此查看更多更全内容