Skip to content

Commit

Permalink
Support unified deployment of Poller and Scaler to GKE
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybell committed Nov 6, 2023
1 parent 1870b08 commit e464de5
Show file tree
Hide file tree
Showing 93 changed files with 8,287 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

defaults:
run:
working-directory: poller/poller-core
working-directory: src/poller/poller-core

strategy:
matrix:
Expand All @@ -32,7 +32,7 @@ jobs:

defaults:
run:
working-directory: scaler/scaler-core
working-directory: src/scaler/scaler-core

strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ terraform/*/*/*.json
.nyc_output

# Kubernetes manifests generated from templates
kubernetes/autoscaler-config/*.yaml
kubernetes/**/autoscaler-config/*.yaml
kubernetes/**/resourcegroup.yaml

# Terratest
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<br />
Home
·
<a href="poller/README.md">Poller component</a>
<a href="src/poller/README.md">Poller component</a>
·
<a href="scaler/README.md">Scaler component</a>
<a href="src/scaler/README.md">Scaler component</a>
·
<a href="forwarder/README.md">Forwarder component</a>
<a href="src/forwarder/README.md">Forwarder component</a>
·
<a href="terraform/README.md">Terraform configuration</a>
·
Expand Down Expand Up @@ -45,9 +45,9 @@ instance.
The Autoscaler monitors your instances and automatically adds or
removes compute capacity to ensure that they stay within the
[recommended maximums for CPU utilization][spanner-max-cpu] and the
[recommended limit for storage per node][spanner-max-storage], plus or minus an
[allowed margin](poller/README.md#margins). Note that the recommended thresholds
are different depending if a Spanner instance is
[recommended limit for storage per node][spanner-max-storage], plus or
minus an [allowed margin](src/poller/README.md#margins). Note that the
recommended thresholds are different depending if a Spanner instance is
[regional or multi-region][spanner-regional].

## Architecture
Expand All @@ -64,7 +64,7 @@ interaction flow:
These can be deployed to either [Cloud Functions][cloud-functions] or
[Google Kubernetes Engine (GKE)][gke], and configured so that the
Autoscaler runs according to a user-defined schedule. In certain deployment
topologies a third component, the [Forwarder](forwarder/README.md), is also
topologies a third component, the [Forwarder][autoscaler-forwarder], is also
deployed.

2. At the specified time and frequency, the Poller component queries the
Expand All @@ -76,9 +76,9 @@ interaction flow:
specific Spanner instance, and some of its corresponding configuration
parameters.

4. Using the chosen [scaling method](scaler/README.md#scaling-methods), the
Scaler compares the Spanner instance metrics against the recommended
thresholds, (plus or minus an [allowed margin](poller/README.md#margins)),
4. Using the chosen [scaling method](src/scaler/README.md#scaling-methods),
the Scaler compares the Spanner instance metrics against the recommended
thresholds, (plus or minus an [allowed margin](src/poller/README.md#margins)),
and determines if the instance should be scaled, and the number of nodes or
processing units that it should be scaled to. If the configured cooldown
period has passed, then the Scaler component requests the Spanner Instance
Expand Down Expand Up @@ -142,8 +142,9 @@ support channels.

<!-- LINKS: https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[autoscaler-poller]: poller/README.md
[autoscaler-scaler]: scaler/README.md
[autoscaler-poller]: src/poller/README.md
[autoscaler-scaler]: src/scaler/README.md
[autoscaler-forwarder]: src/forwarder/README.md
[cloud-functions]: https://cloud.google.com/functions
[cloud-monitoring]: https://cloud.google.com/monitoring
[cloud-logging]: https://cloud.google.com/logging
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Config for Spanner Autoscaler

See [documentation][docs] for installation and configuration instructions.

[docs]: ../../terraform/gke/README.md
[docs]: ../../../terraform/gke/README.md
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Config for Poller component of Spanner Autoscaler

See [documentation][docs] for installation and configuration instructions.

[docs]: ../../../terraform/gke/README.md
[docs]: ../../../../terraform/gke/README.md
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Config for Scaler component of Spanner Autoscaler

See [documentation][docs] for installation and configuration instructions.

[docs]: ../../../terraform/gke/README.md
[docs]: ../../../../terraform/gke/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: autoscaler-config-hourly
namespace: spanner-autoscaler
data:
autoscaler-config-hourly.yaml: |
---
- projectId: ${PROJECT_ID}
instanceId: autoscale-test
# Delete this stanza if using Firestore for state
stateDatabase:
name: spanner
instanceId: autoscale-test-state
databaseId: spanner-autoscaler-state
scalingMethod: DIRECT
units: PROCESSING_UNITS
minSize: 200
maxSize: 200
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: autoscaler-config
namespace: spanner-autoscaler
data:
autoscaler-config.yaml: |
---
- projectId: ${PROJECT_ID}
instanceId: autoscale-test
# Delete this stanza if using Firestore for state
stateDatabase:
name: spanner
instanceId: autoscale-test-state
databaseId: spanner-autoscaler-state
scalingMethod: LINEAR
units: PROCESSING_UNITS
minSize: 100
maxSize: 500
21 changes: 21 additions & 0 deletions kubernetes/unified/autoscaler-pkg/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: autoscaler-pkg
annotations:
config.kubernetes.io/local-config: "true"
info:
description: Config for Spanner autoscaler
16 changes: 16 additions & 0 deletions kubernetes/unified/autoscaler-pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# autoscaler-pkg

## Description

Config for Spanner Autoscaler

### View package content

`kpt pkg tree autoscaler-pkg`
[Details](https://kpt.dev/reference/cli/pkg/tree/)

## Installation

See [documentation][docs] for installation and configuration instructions.

[docs]: ../../../terraform/gke/README.md
23 changes: 23 additions & 0 deletions kubernetes/unified/autoscaler-pkg/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: spanner-autoscaler # kpt-set: ${namespace}
spec:
podSelector: {}
policyTypes:
- Ingress
21 changes: 21 additions & 0 deletions kubernetes/unified/autoscaler-pkg/scaler/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: scaler
annotations:
config.kubernetes.io/local-config: "true"
info:
description: Config for Spanner autoscaler
16 changes: 16 additions & 0 deletions kubernetes/unified/autoscaler-pkg/scaler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# scaler

## Description

Config for Spanner Autoscaler

### View package content

`kpt pkg tree scaler`
[Details](https://kpt.dev/reference/cli/pkg/tree/)

## Installation

See [documentation][docs] for installation and configuration instructions.

[docs]: ../../../../terraform/gke/unified/README.md
51 changes: 51 additions & 0 deletions kubernetes/unified/autoscaler-pkg/scaler/scaler-hourly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: batch/v1
kind: CronJob
metadata:
name: scaler-hourly
namespace: spanner-autoscaler # kpt-set: ${namespace}
spec:
concurrencyPolicy: Forbid
schedule: "1 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: scaler
spec:
containers:
- name: scaler
image: scaler-image # kpt-set: ${scaler_image}
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "256Mi"
env:
- name: AUTOSCALER_CONFIG
value: "/etc/autoscaler-config/autoscaler-config-hourly.yaml"
volumeMounts:
- name: config-volume
mountPath: /etc/autoscaler-config
volumes:
- name: config-volume
configMap:
name: autoscaler-config-hourly
nodeSelector:
iam.gke.io/gke-metadata-server-enabled: "true"
restartPolicy: Never
serviceAccountName: scaler-sa
48 changes: 48 additions & 0 deletions kubernetes/unified/autoscaler-pkg/scaler/scaler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: batch/v1
kind: CronJob
metadata:
name: scaler
namespace: spanner-autoscaler # kpt-set: ${namespace}
spec:
concurrencyPolicy: Forbid
schedule: "*/2 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: scaler
spec:
containers:
- name: scaler
image: scaler-image # kpt-set: ${scaler_image}
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "256Mi"
volumeMounts:
- name: config-volume
mountPath: /etc/autoscaler-config
volumes:
- name: config-volume
configMap:
name: autoscaler-config
nodeSelector:
iam.gke.io/gke-metadata-server-enabled: "true"
restartPolicy: Never
serviceAccountName: scaler-sa
14 changes: 14 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG NODE_VERSION=18
FROM node:${NODE_VERSION}-alpine AS build-env

WORKDIR /usr/src/app
COPY . .

RUN npm config set update-notifier false
RUN npm install

FROM gcr.io/distroless/nodejs${NODE_VERSION}:latest
COPY --from=build-env /usr/src/app /usr/src/app
WORKDIR /usr/src/app/scaler/scaler-core

CMD ["../../index.js"]
Loading

0 comments on commit e464de5

Please sign in to comment.