1、创建configmap
---
apiVersion: v1
data:config.yaml: >-# config.yamlEtcd:Endpoints:- "etcd-server:2379"Username: ""Password: ""Exchanges:#- Name: "Binance"# Symbol: "BTCUSDT"# WSUrl: "wss://fstream.binance.com/ws"- Name: "OKX"Symbol: "BTCUSDT"WSUrl: "wss://ws.okx.com:8443/ws/v5/public"#- Name: "Bybit"# Symbol: "ETHUSDT"# WSUrl: "wss://stream.bybit.com/v5/public/linear"#- Name: "Bitget"# Symbol: "DOGEUSDT"# WSUrl: "wss://ws.bitget.com/mix/v1/stream"# ContractType: "mc"#- Name: "Pyth"# Symbol: "BTCUSDT"# WSUrl: "wss://hermes.pyth.network/ws"# PriceId: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"DatabaseDSN:"abc:defg@tcp(rm-sefdref.mysql.rds.aliyuncs.com:3306)/miniapp"RedisAddr: "0.0.0.0:6379"RedisPassword: "S4t#d%dgrdfer3"RedisDB: 1KafkaBrokers:- "0.0.0.0:3195"BOT_TOKEN: "sefefedsfa:AAELY1TwInw46D3Lhpl0LvpQz2v-DoIq5ww"KafkaPriceUpdateTopic: "price_updates"SupportedCoins:- "BTC"- "ETH"##Chains:# - Name: "ETH"## ChainName: "ETH"## NodeUrl:"https://crimson-frosty-county.quiknode.pro/serfefwaetwegrteyhtdrtyhfhyjhtf/"## ConfirmationNum: 16# ExcludedAddresses: "11","22"## ScanInterval: 60#BaseSlippage: 0.005#Port: "0.0.0.0:8901"LogLevel: "info"Services:- Name: "api_gateway"ServiceID: "api-gateway-1"ServiceHost: "api_gateway"ServicePort: 8080- Name: "spider_service"ServiceID: "spider-service-1"ServiceHost: "spider_service"ServicePort: 50051- Name: "${SERVICE_NAME}"ServiceID: "${SERVICE_ID}"ServiceHost: "${POD_IP}"ServicePort: ${SERVICE_PORT}- Name: "trading_engine_service"ServiceID: "trading-engine-service-1"ServiceHost: "trading_engine_service"ServicePort: 50053- Name: "auth_service"ServiceID: "auth-service-1"ServiceHost: "auth_service"ServicePort: 50054- Name: "user_service"ServiceID: "user-service-1"ServiceHost: "user_service"ServicePort: 50055- Name: "account_service"ServiceID: "account-service-1"ServiceHost: "account_service"ServicePort: 50056- Name: "wallet_service"ServiceID: "wallet-service-1"ServiceHost: "wallet_service"ServicePort: 50057# HttpPort : 8091- Name: "chain_scanner_service"ServiceID: "chain-scanner-service-1"ServiceHost: "chain_scanner_service"ServicePort: 50058- Name: "out_service"ServiceID: "out-service-1"ServiceHost: "out_service"ServicePort: 50059SlippageTiers:tier1:- Threshold: 1000Factor: 0.001- Threshold: 5000Factor: 0.0008tier2:- Threshold: 10000Factor: 0.0005GameOptions:TenantId: 90026ProductCode: UD_OPTIONExitUrl: https://t.me/abc/GoodAccessCode: 15224562686655IvValue: DJIOHFDsaifiajfiwefjqwi63GetUrl: https://abc.pro/saas-option-api/open/tenant/getSaasOptionUrl
kind: ConfigMap
metadata:name: config.yamlnamespace: testresourceVersion: '150039730'
2、创建deployment,其中包含initContainers和containers两部分
---
apiVersion: apps/v1
kind: Deployment
metadata:annotations:k8s.kuboard.cn/displayName: bot-servicelabels:k8s.kuboard.cn/name: bot-servicename: bot-servicenamespace: testresourceVersion: '150036998'
spec:progressDeadlineSeconds: 600replicas: 2revisionHistoryLimit: 10selector:matchLabels:k8s.kuboard.cn/name: bot-servicestrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:creationTimestamp: nulllabels:k8s.kuboard.cn/name: bot-servicespec:containers:- env:- name: SERVICE_IDvalueFrom:fieldRef:apiVersion: v1fieldPath: metadata.nameimage: 'harbor.cuiwjrpcvi.com/bktest/bot_service:test'imagePullPolicy: IfNotPresentname: bot-serviceports:- containerPort: 50052name: adwqdwprotocol: TCPresources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /telegram/shared/configname: config-outputdnsPolicy: ClusterFirsthostAliases:- hostnames:- etcd-serverip: 172.16.1.193imagePullSecrets:- name: harbor-secretinitContainers:- args:- >-apk add --no-cache gettext && envsubst </config-template/config.yaml >/telegram/shared/config/config.yaml;command:- /bin/sh- '-c'env:- name: SERVICE_IDvalueFrom:fieldRef:apiVersion: v1fieldPath: metadata.name- name: POD_IPvalueFrom:fieldRef:apiVersion: v1fieldPath: status.podIP- name: SERVICE_NAMEvalue: bot-service- name: SERVICE_PORTvalue: '50052'image: 'alpine:3.17'imagePullPolicy: IfNotPresentname: bot-service-initresources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /config-templatename: config-template- mountPath: /telegram/shared/config/name: config-outputrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- configMap:defaultMode: 420items:- key: config.yamlpath: config.yamlname: config.yamlname: config-template- emptyDir: {}name: config-output
3、启动deployment并登录容器验证结果
查询configmap文本内容
节点一
cat shared/config/config.yaml
。。。。。。- Name: "bot-service"ServiceID: "bot-service-5c7745fff4-c8w6b"ServiceHost: "172.20.250.31"ServicePort: 50052
。。。。。。
节点二
cat shared/config/config.yaml
。。。。。。- Name: "bot-service"ServiceID: "bot-service-5c7745fff4-8p72g"ServiceHost: "172.20.171.3"ServicePort: 50052
。。。。。。
4、登录etcd查看注册情况
root@iZj6ch896i3lsjbs6cqk2iZ:/data/docker-compose/bot_service# docker exec -it etcd-server /bin/bash
I have no name!@etcd-server:/opt/bitnami/etcd$ etcdctl get --prefix /service
/services/bot/bot-service-5c7745fff4-8p72g
172.20.171.3:50052
/services/bot/bot-service-5c7745fff4-c8w6b
172.20.250.31:50052
至此go程序通过自己提交ip和服务信息注册到etcd已成功完成