Multi-Platform Service Mesh: Kubernetes, Nomad, Bare Metal und VMs mit Consul Connect verbinden
Multi-Platform Service Mesh: Kubernetes, Nomad, Bare Metal und VMs mit Consul Connect verbinden Moderne Infrastrukturen erstrecken sich oft über mehrere
Moderne Infrastrukturen erstrecken sich oft über mehrere Plattformen - Cloud-native Kubernetes-Cluster, HashiCorp Nomad für Orchestrierung, Bare-Metal-Server für leistungskritische Workloads und traditionelle virtuelle Maschinen für Legacy-Anwendungen. Die Verwaltung sicherer Kommunikation zwischen diesen verschiedenen Umgebungen kann komplex und fragmentiert sein.
In diesem umfassenden Leitfaden zeigen wir, wie Sie ein einheitliches Service Mesh aufbauen, das Services nahtlos über Kubernetes, Nomad, Bare-Metal-Server und VMs mit Consul Connect Federation verbindet. Dieser Ansatz bietet konsistente Sicherheit, Service Discovery und Traffic Management, unabhängig davon, wo Ihre Services deployed sind.
Voraussetzungen: Dieser Artikel baut auf Konzepten aus Sichere Kommunikation in Kubernetes mit Consul Connect und Vault Agent Injector auf. Grundkenntnisse in Consul, Service-Mesh-Konzepten und grundlegenden Kubernetes/Nomad-Operationen werden empfohlen.
Unser Multi-Platform Service Mesh schafft eine einheitliche Infrastruktur, die Services nahtlos über verschiedene Deployment-Umgebungen verbindet:
Die Architektur zeigt, wie Consul Connect Federation sichere Kommunikation ermöglicht zwischen:
Alle Plattformen werden durch die Consul Federation vereint, die bietet:
Zuerst etablieren wir die Consul Federation, um unsere verschiedenen Datacenter zu verbinden.
1# consul-dc1-values.yaml - Primary Datacenter in Kubernetes
2global:
3 name: consul
4 image: "hashicorp/consul:1.16.3"
5 datacenter: dc1
6 primaryDatacenter: dc1
7 peering:
8 enabled: true
9 # Aktiviere Federation
10 federation:
11 enabled: true
12 # Aktiviere Mesh Gateways für datacenter-übergreifende Kommunikation
13 meshGateway:
14 enabled: true
15 replicas: 2
16 # Aktiviere ACLs für Sicherheit
17 acls:
18 manageSystemACLs: true
19 createReplicationToken: true
20
21server:
22 enabled: true
23 replicas: 3
24 bootstrapExpected: 3
25 # Aktiviere Connect für Service Mesh
26 connect: true
27 # Expose Federation State Endpoint
28 exposeGossipAndRPCPorts: true
29 ports:
30 # Federation Endpoint
31 serfWAN: 8302
32
33connectInject:
34 enabled: true
35 default: false
36 # Aktiviere Transparent Proxy für einfachere Service-Kommunikation
37 transparentProxy:
38 defaultEnabled: true
39 # Consul Connect Injection Settings
40 consulNode:
41 meta:
42 pod-name: \${HOSTNAME}
43 node-name: \${NODE_NAME}
44 k8sAllowNamespaces: ["*"]
45 k8sDenyNamespaces: ["kube-system", "consul"]
46
47meshGateway:
48 enabled: true
49 replicas: 2
50 service:
51 type: LoadBalancer
52 ports:
53 - port: 443
54 nodePort: null
55 # Aktiviere WAN Federation durch Mesh Gateways
56 wanAddress:
57 source: "Service"
58 port: 443
59
60ui:
61 enabled: true
62 service:
63 type: LoadBalancer
64
65# Aktiviere Metriken-Sammlung
66prometheus:
67 enabled: true
Deploy des primären Consul Datacenters:
1# Erstelle Consul Namespace
2kubectl create namespace consul
3
4# Füge Consul Helm Repository hinzu
5helm repo add hashicorp https://helm.releases.hashicorp.com
6helm repo update
7
8# Installiere primäres Consul Datacenter
9helm install consul-dc1 hashicorp/consul \
10 --namespace consul \
11 --values consul-dc1-values.yaml
12
13# Warte auf Deployment
14kubectl wait --for=condition=ready pod -l app=consul -n consul --timeout=300s
15
16# Hole das Federation Secret für sekundäre Datacenter
17kubectl get secret consul-dc1-federation -n consul -o yaml > consul-federation-secret.yaml
Erstelle Consul-Konfiguration für Nomad-Integration:
1# consul-dc2.hcl - Secondary Datacenter für Nomad Integration
2datacenter = "dc2"
3primary_datacenter = "dc1"
4log_level = "INFO"
5node_name = "consul-dc2"
6bind_addr = "0.0.0.0"
7client_addr = "0.0.0.0"
8
9# Server-Konfiguration
10server = true
11bootstrap_expect = 1
12ui_config {
13 enabled = true
14}
15
16# Aktiviere Connect für Service Mesh
17connect {
18 enabled = true
19}
20
21# Aktiviere Mesh Gateway
22ports {
23 grpc = 8502
24 mesh_gateway = 8443
25}
26
27# Federation-Konfiguration
28retry_join_wan = ["KUBERNETES_MESH_GATEWAY_ADDRESS:443"]
29
30# ACL-Konfiguration
31acl = {
32 enabled = true
33 default_policy = "deny"
34 enable_token_persistence = true
35 tokens {
36 replication = "REPLICATION_TOKEN_FROM_PRIMARY"
37 }
38}
39
40# Auto-Encrypt-Konfiguration
41auto_encrypt {
42 allow_tls = true
43}
1# nomad-dc2.hcl - Nomad-Konfiguration für Service-Mesh-Integration
2datacenter = "dc2"
3name = "nomad-dc2"
4region = "global"
5
6bind_addr = "0.0.0.0"
7
8# Server-Konfiguration
9server {
10 enabled = true
11 bootstrap_expect = 1
12}
13
14# Client-Konfiguration
15client {
16 enabled = true
17 # Aktiviere Task Networking für Connect
18 cni_path = "/opt/cni/bin"
19 cni_config_dir = "/opt/cni/config"
20}
21
22# Consul-Integration
23consul {
24 address = "127.0.0.1:8500"
25 server_service_name = "nomad"
26 client_service_name = "nomad-client"
27 auto_advertise = true
28 server_auto_join = true
29 client_auto_join = true
30
31 # Aktiviere Service-Mesh-Integration
32 connect {
33 enabled = true
34 }
35}
36
37# Plugin-Konfiguration für Networking
38plugin "docker" {
39 config {
40 allow_privileged = true
41 volumes {
42 enabled = true
43 }
44 }
45}
1# web-app-k8s.yaml - Web-Anwendung in Kubernetes
2apiVersion: apps/v1
3kind: Deployment
4metadata:
5 name: web-app
6 namespace: demo
7spec:
8 replicas: 2
9 selector:
10 matchLabels:
11 app: web-app
12 template:
13 metadata:
14 labels:
15 app: web-app
16 annotations:
17 "consul.hashicorp.com/connect-inject": "true"
18 "consul.hashicorp.com/connect-service": "web-app"
19 "consul.hashicorp.com/connect-service-upstreams": "api-service:8080:dc2,database:5432:dc3"
20 "consul.hashicorp.com/transparent-proxy": "true"
21 spec:
22 serviceAccountName: web-app
23 containers:
24 - name: web-app
25 image: nginx:latest
26 ports:
27 - containerPort: 80
28 env:
29 - name: API_SERVICE_URL
30 value: "http://api-service:8080"
31 - name: DATABASE_URL
32 value: "postgres://database:5432/mydb"
33
34---
35apiVersion: v1
36kind: Service
37metadata:
38 name: web-app
39 namespace: demo
40spec:
41 selector:
42 app: web-app
43 ports:
44 - port: 80
45 targetPort: 80
46 type: LoadBalancer
1# api-service-nomad.nomad - API Service in Nomad
2job "api-service" {
3 datacenters = ["dc2"]
4 type = "service"
5
6 group "api" {
7 count = 2
8
9 # Aktiviere Consul Connect
10 service {
11 name = "api-service"
12 port = "http"
13
14 connect {
15 sidecar_service {
16 proxy {
17 upstreams {
18 destination_name = "database"
19 datacenter = "dc3"
20 local_bind_port = 5432
21 }
22 }
23 }
24 }
25 }
26
27 network {
28 mode = "bridge"
29 port "http" {
30 static = 8080
31 to = 8080
32 }
33 }
34
35 task "api-server" {
36 driver = "docker"
37
38 config {
39 image = "hashicorp/http-echo:latest"
40 args = [
41 "-listen", ":8080",
42 "-text", "API Service from Nomad DC2"
43 ]
44 }
45
46 env {
47 DATABASE_URL = "postgres://127.0.0.1:5432/mydb"
48 }
49
50 resources {
51 cpu = 256
52 memory = 256
53 }
54 }
55 }
56}
Deploy des Nomad Jobs:
1# Deploy API Service zu Nomad
2nomad job run api-service-nomad.nomad
3
4# Verifiziere Deployment
5nomad job status api-service
6consul services register api-service
1# install-consul-bare-metal.sh - Installiere Consul auf Bare Metal
2#!/bin/bash
3
4# Download und installiere Consul
5CONSUL_VERSION="1.16.3"
6wget https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip
7unzip consul_${CONSUL_VERSION}_linux_amd64.zip
8sudo mv consul /usr/local/bin/
9
10# Erstelle Consul User und Verzeichnisse
11sudo useradd --system --home /etc/consul.d --shell /bin/false consul
12sudo mkdir -p /opt/consul /etc/consul.d
13sudo chown consul:consul /opt/consul /etc/consul.d
14sudo chmod 755 /opt/consul /etc/consul.d
1# consul-dc3.hcl - Consul-Konfiguration für Bare Metal
2datacenter = "dc3"
3primary_datacenter = "dc1"
4log_level = "INFO"
5node_name = "consul-dc3-server"
6bind_addr = "192.168.1.100" # Ersetzen Sie mit aktueller IP
7client_addr = "0.0.0.0"
8data_dir = "/opt/consul"
9
10# Server-Konfiguration
11server = true
12bootstrap_expect = 1
13
14# Connect-Konfiguration
15connect {
16 enabled = true
17}
18
19ports {
20 grpc = 8502
21 mesh_gateway = 8443
22}
23
24# Join der Federation
25retry_join_wan = ["KUBERNETES_MESH_GATEWAY_ADDRESS:443"]
26
27# ACL-Konfiguration
28acl = {
29 enabled = true
30 default_policy = "deny"
31 enable_token_persistence = true
32 tokens {
33 replication = "REPLICATION_TOKEN_FROM_PRIMARY"
34 agent = "AGENT_TOKEN"
35 }
36}
37
38# Service-Definitionen
39services {
40 name = "database"
41 id = "postgresql-primary"
42 address = "192.168.1.100"
43 port = 5432
44
45 check {
46 tcp = "192.168.1.100:5432"
47 interval = "10s"
48 }
49
50 connect {
51 sidecar_service {
52 port = 21000
53 check {
54 name = "Connect Envoy Sidecar"
55 tcp = "192.168.1.100:21000"
56 interval = "10s"
57 }
58 proxy {
59 config {
60 bind_address = "192.168.1.100"
61 bind_port = 21000
62 }
63 }
64 }
65 }
66}
1# register-vm-service.sh - Registriere VM-basierte Services
2#!/bin/bash
3
4# Installiere Consul Agent auf VM
5curl -fsSL https://releases.hashicorp.com/consul/1.16.3/consul_1.16.3_linux_amd64.zip -o consul.zip
6unzip consul.zip
7sudo mv consul /usr/local/bin/
8
9# Erstelle Service-Definition
10cat > /etc/consul.d/vm-service.json <<EOF
11{
12 "service": {
13 "name": "legacy-app",
14 "id": "legacy-app-vm1",
15 "address": "192.168.1.101",
16 "port": 9090,
17 "tags": ["vm", "legacy"],
18 "check": {
19 "http": "http://192.168.1.101:9090/health",
20 "interval": "30s"
21 },
22 "connect": {
23 "sidecar_service": {
24 "port": 21001,
25 "check": {
26 "name": "Connect Envoy Sidecar",
27 "tcp": "192.168.1.101:21001",
28 "interval": "10s"
29 }
30 }
31 }
32 }
33}
34EOF
35
36# Starte Consul Agent
37consul agent -config-dir=/etc/consul.d -datacenter=dc3 \
38 -retry-join=192.168.1.100 -bind=192.168.1.101
Konfiguriere Service Intentions für plattformübergreifende Sicherheit:
1# Erstelle Service Intentions für datacenter-übergreifende Kommunikation
2
3# Erlaube web-app (K8s DC1) Kommunikation mit api-service (Nomad DC2)
4consul intention create -allow web-app api-service
5
6# Erlaube api-service (Nomad DC2) Kommunikation mit database (Bare Metal DC3)
7consul intention create -allow api-service database
8
9# Erlaube api-service Kommunikation mit legacy-app (VM DC3)
10consul intention create -allow api-service legacy-app
11
12# Verifiziere Intentions
13consul intention list
Erstelle Intention-Konfigurationsdateien für GitOps:
1# service-intentions.yaml
2apiVersion: consul.hashicorp.com/v1alpha1
3kind: ServiceIntentions
4metadata:
5 name: api-service-intentions
6 namespace: consul
7spec:
8 destination:
9 name: api-service
10 sources:
11 - name: web-app
12 action: allow
13 description: "Erlaube web-app Aufruf von api-service"
14 - name: "*"
15 action: deny
16 description: "Verweigere allen anderen Traffic"
17
18---
19apiVersion: consul.hashicorp.com/v1alpha1
20kind: ServiceIntentions
21metadata:
22 name: database-intentions
23 namespace: consul
24spec:
25 destination:
26 name: database
27 sources:
28 - name: api-service
29 action: allow
30 description: "Erlaube api-service Zugriff auf database"
31 - name: "*"
32 action: deny
33 description: "Verweigere allen anderen Traffic"
Konfiguriere Mesh Gateways für sichere datacenter-übergreifende Kommunikation:
1# mesh-gateway-config.yaml
2apiVersion: consul.hashicorp.com/v1alpha1
3kind: ProxyDefaults
4metadata:
5 name: global
6 namespace: consul
7spec:
8 meshGateway:
9 mode: "local"
10 config:
11 protocol: "http"
12
13---
14apiVersion: consul.hashicorp.com/v1alpha1
15kind: ServiceDefaults
16metadata:
17 name: api-service
18 namespace: consul
19spec:
20 protocol: "http"
21 meshGateway:
22 mode: "local"
23
24---
25apiVersion: consul.hashicorp.com/v1alpha1
26kind: ServiceDefaults
27metadata:
28 name: database
29 namespace: consul
30spec:
31 protocol: "tcp"
32 meshGateway:
33 mode: "local"
Wende Mesh Gateway-Konfigurationen an:
1kubectl apply -f mesh-gateway-config.yaml
2kubectl apply -f service-intentions.yaml
Implementiere umfassendes Health Checking über alle Plattformen:
1# health-check-config.yaml
2apiVersion: consul.hashicorp.com/v1alpha1
3kind: ServiceDefaults
4metadata:
5 name: api-service
6 namespace: consul
7spec:
8 protocol: "http"
9 upstreamConfig:
10 defaults:
11 connectTimeoutMs: 5000
12 limits:
13 maxConnections: 50
14 maxPendingRequests: 100
15 passiveHealthCheck:
16 interval: "30s"
17 maxFailures: 3
Konfiguriere Load Balancing-Richtlinien:
1# load-balancer-config.hcl
2Kind = "service-resolver"
3Name = "api-service"
4
5LoadBalancer = {
6 Policy = "round_robin"
7 RingHashConfig = {
8 MinimumRingSize = 1024
9 MaximumRingSize = 8192
10 }
11 HashPolicies = [
12 {
13 Field = "header"
14 FieldValue = "x-user-id"
15 }
16 ]
17}
18
19Failover = {
20 "*" = {
21 Datacenters = ["dc1", "dc3"]
22 }
23}
Implementiere erweiterte Traffic-Verwaltung über Plattformen hinweg:
1# traffic-splitting.yaml
2apiVersion: consul.hashicorp.com/v1alpha1
3kind: ServiceSplitter
4metadata:
5 name: api-service
6 namespace: consul
7spec:
8 splits:
9 - weight: 80
10 service: api-service
11 serviceSubset: v1
12 - weight: 20
13 service: api-service
14 serviceSubset: v2
15
16---
17apiVersion: consul.hashicorp.com/v1alpha1
18kind: ServiceResolver
19metadata:
20 name: api-service
21 namespace: consul
22spec:
23 defaultSubset: v1
24 subsets:
25 v1:
26 filter: "Service.Tags contains v1"
27 v2:
28 filter: "Service.Tags contains v2"
29 failover:
30 "*":
31 datacenters: ["dc1", "dc3"]
Der Aufbau eines Multi-Platform Service Mesh mit Consul Connect ermöglicht es Organisationen:
Diese Architektur bietet die Grundlage für moderne Hybrid- und Multi-Cloud-Deployments, sodass Teams die besten Features jeder Plattform nutzen können, während sie Sicherheit und operative Konsistenz beibehalten.
Wichtige Erkenntnisse:
Bereit, Ihr Multi-Platform Service Mesh zu erstellen? Beginnen Sie mit der Etablierung der Consul Federation zwischen Ihren kritischsten Umgebungen und erweitern Sie schrittweise die Abdeckung, um eine vollständige Plattform-Vereinigung zu erreichen.
Für umfassendes Monitoring und Observability Ihres Multi-Platform Service Mesh, sehen Sie unseren Begleitartikel über Erweiterte Überwachung und Observability für Consul Connect Service Mesh.
Sie interessieren sich für unsere Trainings oder haben einfach eine Frage, die beantwortet werden muss? Sie können uns jederzeit kontaktieren! Wir werden unser Bestes tun, um alle Ihre Fragen zu beantworten.
Hier kontaktieren