因为k8s和kubesphere已经可以满足微服务治理的一些场景,所以很多人就不再使用springcloud进行微服务治理了,但是kubesphere和k8s其实是解决了运维人员的问题,而springcloud才是开发人员的硬核技能,今天我就针对如何部署springcloud的服务网关zuul在k8s中的部署写一个指南手册。
- yaml文件如下:其中这个加入了服务追踪skywalking的agent,具体如何接入请参见此篇文章:
kind: Deployment
apiVersion: apps/v1
metadata:
name: springcloud-gateway
namespace: demo
labels:
app: springcloud-gateway
wayne-app: springcloud
wayne-ns: demo
annotations:
deployment.kubernetes.io/revision: '32'
spec:
replicas: 1
selector:
matchLabels:
app: springcloud-gateway
template:
metadata:
creationTimestamp: null
labels:
app: springcloud-gateway
wayne-app: springcloud
wayne-ns: demo
annotations:
kubesphere.io/restartedAt: '2020-02-04T11:00:04.882Z'
wayne.cloud/controller-kind: deployment
spec:
volumes:
- name: sky-agent-volume
emptyDir: {}
initContainers:
- name: skywalking-agent-gateway
image: >-
registry.cn-beijing.aliyuncs.com/wangxiulong/test:skywalking-agent-6.5
command:
- cp
- '-rf'
- /agent
- /tmp
resources:
limits:
cpu: '0'
memory: '0'
volumeMounts:
- name: sky-agent-volume
mountPath: /tmp
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
containers:
- name: gateway
#zuul的镜像仓库地址和端口
image: 'IP:端口/bims/zuul-gateway'
ports:
- containerPort: 9900
protocol: TCP
env:
- name: SW_AGENT_NAME
value: zlt-gateway
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: 'oap-svc:11800'
resources:
limits:
cpu: '0'
memory: '0'
volumeMounts:
- name: sky-agent-volume
mountPath: /skywalking
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
securityContext:
privileged: false
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 20%
revisionHistoryLimit: 2
progressDeadlineSeconds: 600