springboot+k8s+抛弃springcloud.eureka

2019-12-20| 发布者: admin| 查看: |

springboot开发微服务结构一般运用springcloud全家桶,而整个项目都是容器化的,经过k8s进行编列,而k8s自己也有服务发现机制,所以咱们也能够扔掉springcloud里的eureka,而直接运用k8s自己的服务。
# 增加组件


 dependency 
 groupid org.springframework.cloud /groupid 
 artifactid spring-cloud-starter-netflix-ribbon /artifactid 
 /dependency 
 dependency 
 groupid org.springframework.cloud /groupid 
 artifactid spring-cloud-starter-kubernetes-ribbon /artifactid 
 version 0.3.0.release /version 
 /dependency 
 dependency 
 groupid org.springframework.cloud /groupid 
 artifactid spring-cloud-starter-kubernetes /artifactid 
 version 0.3.0.release /version 
 /dependency 
spring:
 application:
 name: hello-world-service
 cloud:
 config:
 uri: http://config-server-service #集群内部的端口,需要是一个namespace里的,现在装备中心的端口为80
 fail-fast: true

# 增加k8s里用户权限
默许情况下,进行k8s服务调用里会出现用户权限的过错message: forbidden!configured service account doesn't have access.这时需要为k8s账号人物增加权限


kubectl create clusterrolebinding permissive-binding \
 --clusterrole=cluster-admin \
 --user=admin \
 --user=kubelet \
 --group=system:serviceaccounts