go-zero 从零到 k8s 部署

启动:

注意事项: dockerfile 文件配置了 LOCAL_HOST 环境变量

1、项目目录下执行 ./docker.sh  脚本生成 rpc服务docker镜像
   ./docker.sh

2、docker-compose-db 创建 mysql redis etcd 容器
  执行命令:
  docker-compose -f docker-compose-db.yml up -d

注意:etcd 使用 k8s 自带的,启动 k8s 之后,需要手动执行 命令:
    etcd --advertise-client-urls 'http://0.0.0.0:2379' --listen-client-urls 'http://0.0.0.0:2379'
    注释:--listen-client-urls:对外提供服务的地址:比如http://ip:2379,http://127.0.0.1:2379,客户端会连接到这里和 etcd 交互。
        --advertise-client-urls:对外公告的该节点客户端监听地址,这个值会告诉集群中其他节点。
    website: https://www.cnblogs.com/xishuai/p/docker-etcd.html

3、docker-compose-prom 创建 prometheus grafana 容器
  执行命令:
  docker-compose -f docker-compose-prom.yml up -d

注意:
    http://127.0.0.1:9090/ 普罗米修斯 web url
    http://localhost:3000/ Grafana web url
  
4、docker-compose 创建rpc服务容器,  rpc 服务基于依赖于etcd 服务
   执行命令:
   docker-compose up -d      

rpc 服务

1、定义数据边界
2、数据库相互隔离、通过 rpc 相互调用
3、服务间相互调用, 例如:add 之前需要调用 check 服务 
    1. 配置 add.yaml 文件添加 check 配置项
    2. Config addRpc 服务下 添加配置项
    3. ServiceContext 添加服务上下文配置
    4. 在 AddLogic 添加逻辑中 调用 check 服务

编写 k8s 服务

方法一

注意事项:上 k8s 部署的时候需要注意 etcd 配置,etcd 在 k8s 集群内服务地址

如何查找 etcd 在 k8s 的内部地址, 步骤如下

首先可以通过终端执行命令:docker ps | grep etcd 查找到 k8s 的 etcd 容器 k8s_etcd_etcd-docker-desktop_kube-system_c7cc6a3c3118f127f5fd469ef69477e0_2

然后执行命令: kubectl get pods -n kube-system 查找到 etcd 的 pod 名称 etcd-docker-desktop

最后执行命令: kubectl describe pod etcd-docker-desktop -n kube-system 查找到 pod 的详情,

advertise-client-urls=https://192.168.65.3:2379 可以找到 etcd 的内部 IP

方法二

k8s dashboard

执行 kubectl proxy 命令

在浏览器访问 http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

命名空间选择 kube-system 然后找到 etcd 的 pod, 点击进入 pod 就可以看到详情。可以找到 etcd 的内部 IP

启动 kubernetes-dashboard 命令

生成 k8s checkrpc.yaml 配置文件

goctl kube deploy -name checkrpc -namespace discov -image checkrpc:0.0.1 -o checkrpc.yaml -port 8081

k8s 部署服务 如果 checkrpc namespace 不存在的话,请先通过 kubectl create namespace checkrpc 创建

kubectl create namespace discov

首先部署 etcd

kubectl apply -f etcd.yaml 

部署

kubectl apply -f checkrpc.yaml 

测试

kubectl run -i --tty --rm cli --image=checkrpc:0.0.1 -n discov -- sh

生成 k8s addrpc.yaml 配置文件

goctl kube deploy -name addrpc -namespace discov -image addrpc:0.0.1 -o addrpc.yaml -port 8080

k8s 部署服务 如果 addrpc namespace 不存在的话,请先通过 kubectl create namespace addrpc 创建

kubectl create namespace discov

部署

kubectl apply -f addrpc.yaml 

测试

kubectl run -i --tty --rm cli --image=addrpc:0.0.1 -n discov -- sh

生成 k8s apirpc.yaml 配置文件

goctl kube deploy -name apirpc -namespace discov -image apirpc:0.0.1 -o apirpc.yaml -port 8888

k8s 部署服务 如果 apirpc namespace 不存在的话,请先通过 kubectl create namespace apirpc 创建

kubectl create namespace discov

部署

kubectl apply -f apirpc.yaml 

测试

kubectl run -i --tty --rm cli --image=apirpc:0.0.1 -n discov -- sh

Similar Resources

A helm v3 plugin to adopt existing k8s resources into a new generated helm chart

helm-adopt Overview helm-adopt is a helm plugin to adopt existing k8s resources into a new generated helm chart, the idea behind the plugin was inspir

Dec 15, 2022

General Pod Autoscaler(GPA) is a extension for K8s HPA, which can be used not only for serving, also for game.

General Pod Autoscaler(GPA) is a extension for K8s HPA, which can be used not only for serving, also for game.

Introduction General Pod Autoscaler(GPA) is a extension for K8s HPA, which can be used not only for serving, also for game. Features Compatible with a

Aug 19, 2022

Running OpenFaas Pro on Linode K8s (feat. Aiven and Pulumi)

Running OpenFaas Pro on Linode K8s (feat. Aiven and Pulumi) Alex Ellis did a great job, when he wrote a tutorial about Event-driven OpenFaaS with Mana

Apr 26, 2022

基于 K8S 的云应用平台 后端代码

基于 K8S 的云应用平台 后端代码

cloudApp 基于 K8S 的云应用平台 cloud-app是基于k8s的简单易用的云应用平台,借助它可以快速安装部署各种应用,或者一键安装helm chart包,大幅提升k8s应用部署的效率。注意cloud-app的定位是应用的安装部署等操作,不是k8s的管理界面。 这里是后端代码,前端代码见

Jan 8, 2023

The k8s-generic-webhook is a library to simplify the implementation of webhooks for arbitrary customer resources (CR) in the operator-sdk or controller-runtime.

k8s-generic-webhook The k8s-generic-webhook is a library to simplify the implementation of webhooks for arbitrary customer resources (CR) in the opera

Nov 24, 2022

Kubedd – Check migration issues of Kubernetes Objects while K8s upgrade

Kubedd – Check migration issues of Kubernetes Objects while K8s upgrade

Dec 19, 2022

Converts your k8s YAML to a cdk8s Api Object.

kube2cdk8s Converts your k8s YAML to a cdk8s Api Object. Uses Pulumi's kube2pulumi as a base. Dependencies 1. pulumi cli 2. pulumi kubernetes provider

Oct 18, 2022

quick debug program running in the k8s pod

quick debug program running in the k8s pod

quick-debug English | 中文 What Problem To Solve As the k8s becomes more and more popular, most projects are deployed in k8s, and so is the development

Apr 1, 2022

This project for solving the problem of chaincode being free from k8s control

This project for solving the problem of chaincode being free from k8s control

Peitho - Hyperledger Fabric chaincode Cloud-native managed system The chaincode of Hyperledger Fabric can be handed over to k8s for management, which

Aug 14, 2022
K8s-cinder-csi-plugin - K8s Pod Use Openstack Cinder Volume

k8s-cinder-csi-plugin K8s Pod Use Openstack Cinder Volume openstack volume list

Jul 18, 2022
K8s-ingress-health-bot - A K8s Ingress Health Bot is a lightweight application to check the health of the ingress endpoints for a given kubernetes namespace.

k8s-ingress-health-bot A K8s Ingress Health Bot is a lightweight application to check the health of qualified ingress endpoints for a given kubernetes

Jan 2, 2022
K8s-go-structs - All k8s API Go structs

k8s-api go types Why? Its nice to have it all in a single package. . |-- pkg |

Jul 17, 2022
k8s-image-swapper Mirror images into your own registry and swap image references automatically.
k8s-image-swapper Mirror images into your own registry and swap image references automatically.

k8s-image-swapper Mirror images into your own registry and swap image references automatically. k8s-image-swapper is a mutating webhook for Kubernetes

Dec 27, 2022
top for k8s
top for k8s

ktop A visualized monitoring dashboard for Kubernetes. kubectl also has top subcommand, but it is not able to: Watch usages regularly for Pod/Node Com

Aug 29, 2022
:recycle: Now you can easily rollback to previous deployed images whatever you want on k8s environment

EasyRollback EasyRollback is aim to easy rollback to previous images that deployed on k8s environment Installation You should have go installation fir

Dec 24, 2022
Kilo is a multi-cloud network overlay built on WireGuard and designed for Kubernetes (k8s + wg = kg)

Kilo Kilo is a multi-cloud network overlay built on WireGuard and designed for Kubernetes. Overview Kilo connects nodes in a cluster by providing an e

Jan 1, 2023
A k8s vault webhook is a Kubernetes webhook that can inject secrets into Kubernetes resources by connecting to multiple secret managers
A k8s vault webhook is a Kubernetes webhook that can inject secrets into Kubernetes resources by connecting to multiple secret managers

k8s-vault-webhook is a Kubernetes admission webhook which listen for the events related to Kubernetes resources for injecting secret directly from sec

Oct 15, 2022
A controller to create K8s Ingresses for Openshift routes.

route-to-ingress-operator A controller to create corresponding ingress.networking.k8s.io/v1 resources for route.openshift.io/v1 TODO int port string p

Jan 7, 2022
A K8s ClusterIP HTTP monitoring library based on eBPF

Owlk8s Seamless RED monitoring of k8s ClusterIP HTTP services. This library provides RED (rate,error,duration) monitoring for all(by default but exclu

Jun 16, 2022