go-micro 基于k8s做服务发现
go-micro 可以基于k8s做服务发现,需要开启RBAC
制作镜像
micro-hello 是基于go-micro框架的服务
Dokerfile
FROM alpine
ADD micro-hello /micro-hello
ENTRYPOINT /micro-hello --registry kubernetes
执行命令生成镜像
~# docker build . -t micro-hello-default-k8s:latest
创建serviceAccount
serviceAccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: micro-services
- 执行命令 kubectl apply -f serviceAccount.yaml
- 查看serviceAccount是否创建成功
~$ kubectl get sa
NAME SECRETS AGE
default 1 4d20h
micro-services 1 3h24m
~$ kubectl describe sa micro-services
Name: micro-services
Namespace: default
Labels: <none>
Annotations: <none>
Image pull secrets: <none>
Mountable secrets: micro-services-token-qbhfz
Tokens: micro-services-token-qbhfz
Events: <none>
创建clusterRole
clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: micro-registry
rules:
- apiGroups:
- ""
resources<