我写了一个小应用程序,它支持Akka Cluster的群集。我想通过支持扩展将其部署到Kubernetes。这是我的docker-compose.yml
文件:
version: '3.5'
networks:
cluster-network:
services:
seed:
networks:
- cluster-network
image: akka-cluster-server
ports:
- '2552:2552'
- '8000:8000'
environment:
SERVER_IP: 0.0.0.0
CLUSTER_IP: seed
CLUSTER_SEED_IP: seed
node1:
networks:
- cluster-network
image: akka-cluster-server
ports:
- '8001:8000'
environment:
SERVER_IP: 0.0.0.0
CLUSTER_IP: node1
CLUSTER_PORT: 1600
CLUSTER_SEED_IP: seed
CLUSTER_SEED_PORT: 2552
node2:
networks:
- cluster-network
image: akka-cluster-server
ports:
- '8002:8000'
environment:
SERVER_IP: 0.0.0.0
CLUSTER_IP: node2
CLUSTER_PORT: 1600
CLUSTER_SEED_IP: seed
CLUSTER_SEED_PORT: 2552
三个实例之间共享网络。请注意,node1
和node2
使用seed
的DNS名称进行连接。我编写了简单的部署和服务。
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: akka-cluster
spec:
selector:
matchLabels:
app: akka-cluster
replicas: 2
template:
metadata:
labels:
app: akka-cluster
spec:
containers:
- name: server-seed
image: akka-cluster-server
imagePullPolicy: Never
ports:
- containerPort: 8000
- containerPort: 2552
env:
- name: SERVER_IP
value: 0.0.0.0
- name: CLUSTER_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: CLUSTER_SEED_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: CLUSTER_PORT
value: "1600"
- name: CLUSTER_SEED_PORT
value: "2552"
服务:
apiVersion: v1
kind: Service
metadata:
name: akka-cluster-service
spec:
type: LoadBalancer
selector:
app: akka-cluster
ports:
- protocol: TCP
port: 8080
targetPort: 8000
请注意,在这种情况下,缩放副本时,容器将连接到自身(CLUSTER_SEED_IP
)而不是种子节点。
如何正确将我的docker-compose.yml
转换为Kubernetes部署/服务?
答案 0 :(得分:1)
要正确地“翻译” docker-compose,您应该创建两组部署+服务:一组用于种子,另一组用于节点。
如果您需要将所有实例都列为种子,那么更好的方法可能是通过statefulset实现。您可以检查一下,例如https://github.com/IBM/Akka-cluster-deploy-kubernetes/blob/master/deploy/kubernetes/resources/myapp/myapp-statefulset.json