springboot+k8s+抛弃springcloud.eureka
https://www.cnblogs.com/lori/p/12048743.html
springboot development of micro-services framework generally used springcloud family bucket, and the entire project is containerized, orchestrated by k8s, and k8s themselves have a service discovery mechanism, so we can abandon springcloud in the eureka, and direct use k8s own service .
# Add components
<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>
important point
- Application.name the same k8s service name, that feign in the name of the service
- You must be open @EnableDiscoveryClient comment
- springcloud configuration center needs and projects in a namespace that k8s of clusterIp not cross namespace, if multiple namespace need nodeport mode
- When using feign, its services also need to be under the same namespace
spring:
application:
name: hello-world-service
cloud: config: uri: http://config-server-service #集群内部的端口,需要是一个namespace里的,目前配置中心的端口为80 fail-fast: true
# Add k8s in user permissions
by default, error k8s service call will appear in the user's permission Message: Forbidden!Configured service account doesn't have access.
then you need to add permissions for the account role k8s
kubectl create clusterrolebinding permissive-binding \
--clusterrole=cluster-admin \
--user=admin \
--user=kubelet \
--group=system:serviceaccounts
springboot development of micro-services framework generally used springcloud family bucket, and the entire project is containerized, orchestrated by k8s, and k8s themselves have a service discovery mechanism, so we can abandon springcloud in the eureka, and direct use k8s own service .
# Add components
<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>
important point
- Application.name the same k8s service name, that feign in the name of the service
- You must be open @EnableDiscoveryClient comment
- springcloud configuration center needs and projects in a namespace that k8s of clusterIp not cross namespace, if multiple namespace need nodeport mode
- When using feign, its services also need to be under the same namespace
spring:
application:
name: hello-world-service
cloud: config: uri: http://config-server-service #集群内部的端口,需要是一个namespace里的,目前配置中心的端口为80 fail-fast: true
# Add k8s in user permissions
by default, error k8s service call will appear in the user's permission Message: Forbidden!Configured service account doesn't have access.
then you need to add permissions for the account role k8s
kubectl create clusterrolebinding permissive-binding \
--clusterrole=cluster-admin \
--user=admin \
--user=kubelet \
--group=system:serviceaccounts