Skip to content

Commit 9f2d5cb

Browse files
committed
feat: expose Elasticsearch through GCP Internal LB, backend keep using https, but frontend on http and port 80 due to service limitations
1 parent e22cdaa commit 9f2d5cb

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

bin/demo.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,28 @@ __create_gke() {
5353
--max-unavailable-upgrade 0 \
5454
--enable-autorepair
5555

56+
__init_internal_loadbalancer
5657
__init $@
5758
}
5859

60+
__init_internal_loadbalancer() {
61+
# GCE internal load balancer requires a
62+
# proxy-only subnet in the same region and VPC
63+
64+
# IMPORTANT: this IPv4 is ONLY for GCP default us-central1, you need to update the range
65+
# to match your desired subnet settings
66+
# Check if proxy-only subnet already exists, L7 LB only
67+
if ! gcloud compute networks subnets describe proxy-only-subnet \
68+
--region=$region --network=default >/dev/null 2>&1; then
69+
echo "Creating proxy-only subnet for internal load balancer..."
70+
gcloud compute networks subnets create proxy-only-subnet \
71+
--purpose=REGIONAL_MANAGED_PROXY --role=ACTIVE --region=$region \
72+
--network=default --range=10.120.0.0/23
73+
else
74+
echo "proxy-only-subnet already exists, skipping creation."
75+
fi
76+
}
77+
5978
# setup the deployment enviroment for Elastic Stack
6079
__init() {
6180
# Set kubectl to target the created cluster
@@ -144,6 +163,7 @@ __password_reset() {
144163
__status() {
145164
passwd=$(__password)
146165
lb_ip=`kubectl get services ${es_cluster_name}-es-http -o jsonpath='{.status.loadBalancer.ingress[0].ip}'`
166+
ilb_ip=`kubectl get ingress ${es_cluster_name}-es-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}'`
147167

148168
kbn_ip=`kubectl get service dingo-demo-kbn-kb-http -o jsonpath='{.status.loadBalancer.ingress[0].ip}'`
149169
kbn_port=5601
@@ -152,11 +172,13 @@ __status() {
152172
echo; echo "================================="; echo
153173
echo "Elasticsearch status: "
154174
curl -u "elastic:$passwd" -k "https://$lb_ip:9200"
175+
curl -u "elastic:$passwd" "http://$ilb_ip"
155176

156177
echo; echo "---------------------------------"; echo
157178

158-
echo "Kibana: " ${kbn_url}
159-
echo "Elasticsearch: " "https://$lb_ip:9200"
179+
echo "Kibana public address: " ${kbn_url}
180+
echo "Elasticsearch public address: " "https://$lb_ip:9200"
181+
echo "Elasticsearch internal address: " "http://$ilb_ip"
160182
echo "Username: " elastic
161183
echo "Password: " ${passwd}
162184
echo "================================="; echo

templates/es.demo.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,20 @@ spec:
66
version: 8.18.3
77
http:
88
service:
9+
metadata:
10+
annotations:
11+
cloud.google.com/app-protocols: '{"https":"HTTPS"}'
12+
cloud.google.com/neg: '{"ingress": true}'
13+
cloud.google.com/backend-config: '{"ports": {"9200":"dingo-demo-es-backendconfig"}}'
914
spec:
10-
type: LoadBalancer
15+
#type: LoadBalancer
16+
#type: NodePort
17+
type: ClusterIP
18+
ports:
19+
- name: https
20+
port: 9200
21+
protocol: TCP
22+
targetPort: 9200
1123
secureSettings:
1224
- secretName: gcs-credentials
1325
nodeSets:
@@ -23,6 +35,7 @@ spec:
2335
node.attr.zone: us-central1-a
2436
#node.remote_cluster_client: true
2537
xpack.security.authc.anonymous.roles: monitoring_user
38+
xpack.security.authc.anonymous.authz_exception: false
2639
volumeClaimTemplates:
2740
- metadata:
2841
name: elasticsearch-data
@@ -96,3 +109,43 @@ spec:
96109
matchLabels:
97110
elasticsearch.k8s.elastic.co/cluster-name: dingo-demo
98111
topologyKey: kubernetes.io/hostname
112+
113+
---
114+
apiVersion: networking.k8s.io/v1
115+
kind: Ingress
116+
metadata:
117+
name: dingo-demo-es-ingress
118+
annotations:
119+
kubernetes.io/ingress.allow-http: "true"
120+
kubernetes.io/ingress.class: "gce-internal"
121+
spec:
122+
rules:
123+
- http:
124+
paths:
125+
- path: /
126+
pathType: Prefix
127+
backend:
128+
service:
129+
name: dingo-demo-es-http
130+
port:
131+
number: 9200
132+
133+
---
134+
apiVersion: cloud.google.com/v1
135+
kind: BackendConfig
136+
metadata:
137+
name: dingo-demo-es-backendconfig
138+
spec:
139+
healthCheck:
140+
type: HTTPS
141+
port: 9200
142+
requestPath: /
143+
checkIntervalSec: 15
144+
timeoutSec: 10
145+
healthyThreshold: 1
146+
unhealthyThreshold: 10
147+
sessionAffinity:
148+
affinityType: "CLIENT_IP"
149+
timeoutSec: 60
150+
connectionDraining:
151+
drainingTimeoutSec: 300

0 commit comments

Comments
 (0)