Skip to content

Commit

Permalink
doc: Add quickstart guide to README (#126)
Browse files Browse the repository at this point in the history
Adds quickstart instructions to the README. This tells the user how to follow the existing
Cloud SQL Quickstart on GKE guide, adding a few extra steps in the middle, to try out
the operator.
  • Loading branch information
hessjcg authored Dec 12, 2022
1 parent 154ba08 commit 891d6d8
Show file tree
Hide file tree
Showing 5 changed files with 354 additions and 21 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ help: ## Display this help.
install_tools: remove_tools all_tools ## Installs all development tools

.PHONY: generate
generate: ctrl_generate ctrl_manifests go_lint tf_lint installer reset_image add_copyright_header go_fmt yaml_fmt ## Runs code generation, format, and validation tools
generate: ctrl_generate ctrl_manifests go_lint tf_lint installer reset_image add_copyright_header update_version_in_docs go_fmt yaml_fmt ## Runs code generation, format, and validation tools

.PHONY: build
build: generate build_push_docker ## Builds and pushes the docker image to tag defined in envvar IMG
Expand Down Expand Up @@ -125,6 +125,12 @@ yaml_fmt: # Automatically formats all yaml files
add_copyright_header: # Add the copyright header
go run github.com/google/addlicense@latest *

.PHONY: update_version_in_docs
update_version_in_docs: # Fix version numbers that appear in the markdown documentation
# Update links to the install script
find . -name '*.md' | xargs sed -i.bak -E 's|storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy-operator/[^/]+/install.sh|storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy-operator/v$(VERSION)/install.sh|g' && \
find . -name '*.md.bak' | xargs rm -f

.PHONY: build_push_docker
build_push_docker: # Build docker image with the operator. set IMG env var before running: `IMG=example.com/img:1.0 make build`
@test -n "$(IMG)" || ( echo "IMG environment variable must be set to the public repo where you want to push the image" ; exit 1)
Expand Down
84 changes: 64 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,78 @@ which specifies the Cloud SQL Auth Proxy configuration for a workload. The opera
reads this resource and adds a properly configured Cloud SQL Auth Proxy container
to the matching workload pods.

## Setting up the initial project
These commands will be run to initialize the kubebuilder project
## Installation

Check for the latest version on the [releases page][releases] and use the
following instructions.

```
# Get the kubebuilder binary
mkdir -p .bin
curl -L -o .bin/kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.6.0/kubebuilder_$(go env GOOS)_$(go env GOARCH)"
chmod a+x .bin/kubebuilder
Confirm that kubectl can connect to your kubernetes cluster.

# Clean up the root dir for kubebuilder
rm -rf Makefile main.go go.mod go.sum cover.out
```shell
kubectl cluster-info
```

mkdir -p .bin/tmp/
mv docs .bin/tmp/
mv version.txt .bin/tmp/
Run the following command to install the cloud sql proxy operator into
your kubernetes cluster:

rm -rf bin
.bin/kubebuilder init --owner "Google LLC" --project-name "cloud-sql-proxy-operator" --domain cloud.google.com --repo github.com/GoogleCloudPlatform/cloud-sql-proxy-operator
```shell
curl https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy-operator/v0.0.4-dev/install.sh | bash
```

mv .bin/tmp/* .
Confirm that the operator is installed and running by listing its pods:

```shell
kubectl get pods -n cloud-sql-proxy-operator-system
```

Then, to create the CRD for Workload
```
.bin/kubebuilder create api --group cloudsql --version v1alpha1 --kind AuthProxyWorkload --controller --resource --force
.bin/kubebuilder create webhook --group cloudsql --version v1alpha1 --kind AuthProxyWorkload --defaulting --programmatic-validation
```
## Usage

See the [Quick Start Guide](docs/quick-start.md) for a description of basic usage.
Additional usage may be found in the [Examples](docs/examples/).

## Frequently Asked Questions

### Why would I use the Cloud SQL Auth Proxy Operator?

The Cloud SQL Auth Proxy Operator gives you an easy way to add a proxy container
to your kubernetes workloads, configured correctly for production use.

Writing the kubernetes configuration for a proxy to the production level requires
a great deal of deep kubernetes and proxy knowledge. The Cloud SQL Proxy team has
worked to encapsulate that knowledge in this operator. This saves you from having
to know all the details to configure your proxy.

## Reference Documentation
- [Quick Start Guide](docs/quick-start.md)
- [Cloud SQL Proxy](/GoogleCloudPlatform/cloud-sql-proxy)
- [Developer Getting Started](docs/dev.md)
- [Developing End-to-End tests](docs/e2e-tests.md)
- [Contributing](docs/contributing.md)
- [Code of Conduct](docs/code-of-conduct.md)
- [Examples](docs/examples/)

## Support policy

### Major version lifecycle

This project uses [semantic versioning](https://semver.org/), and uses the
following lifecycle regarding support for a major version:

**Active** - Active versions get all new features and security fixes (that
wouldn’t otherwise introduce a breaking change). New major versions are
guaranteed to be "active" for a minimum of 1 year.
**Deprecated** - Deprecated versions continue to receive security and critical
bug fixes, but do not receive new features. Deprecated versions will be publicly
supported for 1 year.
**Unsupported** - Any major version that has been deprecated for >=1 year is
considered publicly unsupported.

## Contributing

Contributions are welcome. Please, see the [CONTRIBUTING][contributing] document
for details.

Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms. See
[Contributor Code of Conduct][code-of-conduct] for more information.

33 changes: 33 additions & 0 deletions docs/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Development

# How this project was created
This project was initially scaffolded by `kubebuilder` 3.6.0. These are the
commands initially used to set up the project.

```
# Get the kubebuilder binary
mkdir -p .bin
curl -L -o .bin/kubebuilder "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.6.0/kubebuilder_$(go env GOOS)_$(go env GOARCH)"
chmod a+x .bin/kubebuilder
# Clean up the root dir for kubebuilder
rm -rf Makefile main.go go.mod go.sum cover.out
mkdir -p .bin/tmp/
mv docs .bin/tmp/
mv version.txt .bin/tmp/
rm -rf bin
.bin/kubebuilder init --owner "Google LLC" --project-name "cloud-sql-proxy-operator" --domain cloud.google.com --repo github.com/GoogleCloudPlatform/cloud-sql-proxy-operator
mv .bin/tmp/* .
```

Then, to create the CRD for Workload
```
.bin/kubebuilder create api --group cloudsql --version v1alpha1 --kind AuthProxyWorkload --controller --resource --force
.bin/kubebuilder create webhook --group cloudsql --version v1alpha1 --kind AuthProxyWorkload --defaulting --programmatic-validation
```


115 changes: 115 additions & 0 deletions docs/examples/deployment-postgres-tcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# 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.

###
# This example demonstrates how to use environment variables set by the
# Cloud SQL Proxy Operator to connect to your database.

##
# Create an AuthProxyWorkload to hold the configuration for your
# Cloud SQL Proxy containers.

apiVersion: cloudsql.cloud.google.com/v1alpha1
kind: AuthProxyWorkload
metadata:
name: authproxyworkload-sample
spec:
workloadSelector:
kind: "Deployment" # Applies to a "Deployment"
name: "gke-cloud-sql-app" # named 'gke-cloud-sql-app'
instances:
- connectionString: "my-project:us-central1:instance" # from your Cloud SQL Database instance
portEnvName: "DB_PORT" # Will set an env var named 'DB_PORT' to the database port
hostEnvName: "DB_HOST" # Will set an env var named 'DB_HOST' to the proxy's host, 127.0.0.1
---
##
# Put the database name, username, and password into a kubernetes secret
# Update the values below as needed for your environment
#
# WARNING: Do not store passwords in a source code file. It is a bad
# way to keep your secrets safe.
#
# Instead, use kubectl to create the secret using an interactive command
# so that your password is not stored in your source code.
#
# kubectl create secret generic gke-cloud-sql-operator-demo \
# --from-literal=DB_NAME=your_db_name \
# --from-literal=DB_USER=your_db_user \
# --from-literal=DB_PASS=your_db_password
#
apiVersion: v1
kind: Secret
metadata:
name: gke-cloud-sql-operator-demo
type: Opaque
data:
DB_PASS: cGFzc3dvcmQ= # "password"
DB_NAME: cG9zdGdyZXM= # "postgres"
DB_USER: dGVzdHVzZXI= # "testuser"
---
##
# Create a deployment for your application that uses environment variables
# set by the proxy to connect to the database.
apiVersion: apps/v1
kind: Deployment
metadata:
name: gke-cloud-sql-app
spec:
selector:
matchLabels:
app: gke-cloud-sql-app
template:
metadata:
labels:
app: gke-cloud-sql-app
spec:
containers:
- name: gke-cloud-sql-app
image: postgres
livenessProbe:
initialDelaySeconds: 60
periodSeconds: 30
failureThreshold: 3
exec:
command: ["/bin/sh", "-c", "psql --host=$DB_HOST --port=$DB_PORT --username=$DB_USER '--command=select 1' --echo-queries --dbname=$DB_NAME"]
command:
- "/bin/sh"
- "-e"
- "-c"
- "sleep 10 ; psql --host=$DB_HOST --port=$DB_PORT --username=$DB_USER '--command=select 1' --echo-queries --dbname=$DB_NAME ; sleep 3600"
env:
- name: DB_HOST
value: "set-by-operator"
- name: DB_PORT
value: "set-by-operator"
- name: DB_USER
valueFrom:
secretKeyRef:
name: gke-cloud-sql-operator-demo
key: DB_USER
- name: DB_USER
valueFrom:
secretKeyRef:
name: gke-cloud-sql-operator-demo
key: DB_USER
- name: PGPASSWORD # The env name PGPASSWORD is specific to the psql command.
valueFrom:
secretKeyRef:
name: gke-cloud-sql-operator-demo
key: DB_PASS
- name: DB_NAME
valueFrom:
secretKeyRef:
name: gke-cloud-sql-operator-demo
key: DB_NAME
Loading

0 comments on commit 891d6d8

Please sign in to comment.