这里我们在前面已经完成了grpc项目的编写,打包,上传镜像(详见:《Grpc框架实战微服务调用系列》),本文的话我们来使用普通的方式部署一下这里的Grpc项目。下面直接开始:
1)首先创建一个名称空间,我们把这个grpc的demo放在指定的名称空间里面去,这里我们的名称空间是:grpc-demo,如下图:
2)首先部署grpc-server,部署的yaml文件内容如下:
--- apiVersion: apps/v1 kind: Deployment metadata: annotations: k8s.kuboard.cn/displayName: grpc-server labels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: grpc-server name: grpc-server namespace: grpc-demo resourceVersion: '7585' spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: grpc-server strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: annotations: kubectl.kubernetes.io/restartedAt: '2024-01-04T14:36:15+08:00' creationTimestamp: null labels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: grpc-server spec: containers: - env: - name: grpc.server.port value: '3001' - name: GRPC_SERVER_PORT value: '3001' image: 'a85791d9bf0b9ade/grpc-server:1.0' imagePullPolicy: IfNotPresent name: grpc-server resources: limits: cpu: '1' memory: 1Gi requests: cpu: '1' memory: 1Gi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 --- apiVersion: v1 kind: Service metadata: annotations: {} labels: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: grpc-server name: grpc-server namespace: grpc-demo resourceVersion: '5553' spec: clusterIP: 10.233.242.85 clusterIPs: - 10.233.242.85 internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - name: apqsnd port: 3001 protocol: TCP targetPort: 3001 selector: k8s.kuboard.cn/layer: svc k8s.kuboard.cn/name: grpc-server sessionAffinity: ClientIP sessionAffinityConfig: clientIP: timeoutSeconds: 10800 type: ClusterIP
备注:
1、我这里主要使用kuboard进行可视化部署的,部署后的yaml文件内容如上,如果大家要使用它yaml部署,可以参考上面的yaml文件进行精简。
grpcserver部署完毕之后,如下图:
最后当然我们要看看启动日志是否报错:
可以看到这里的server启动很成功,没用任何报错。
3)接着我们部署client,同样的部署后的yaml文件内容示例如下:
--- apiVersion: apps/v1 kind: Deployment metadata: annotations: {} labels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: grpc-client name: grpc-client namespace: grpc-demo resourceVersion: '8012' spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: grpc-client strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: grpc-client spec: containers: - image: 'a85791d9bf0b9ade/grpc-client:1.0' imagePullPolicy: IfNotPresent name: grpc-client resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 --- apiVersion: v1 kind: Service metadata: annotations: {} labels: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: grpc-client name: grpc-client namespace: grpc-demo resourceVersion: '8015' spec: clusterIP: 10.233.250.118 clusterIPs: - 10.233.250.118 externalTrafficPolicy: Cluster internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - name: brsntb nodePort: 32555 port: 8088 protocol: TCP targetPort: 8088 selector: k8s.kuboard.cn/layer: web k8s.kuboard.cn/name: grpc-client sessionAffinity: None type: NodePort
备注:
1、我这里主要使用kuboard进行可视化部署的,部署后的yaml文件内容如上,如果大家要使用它yaml部署,可以参考上面的yaml文件进行精简。
部署client完毕之后,如下图:
当然我们需要继续看下日志是否启动有问题,日志如下:
可以看到日志完全没用问题,此时我们的部署层级图如下:
4)测试
这里我们的client端使用nodeport的形式暴露的服务,所以我们可以直接通过nodeip+端口的形式访问服务。示例如下:
我们通过浏览器访问成功了,所以这里我们使用kuboard在k8s里面进行普通的部署是完全没问题的。
还没有评论,来说两句吧...