Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: restructure directories and add quickstart #115

Merged
merged 20 commits into from May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/cloudbuild/pos-pr-open-to-main.yaml
Expand Up @@ -23,7 +23,7 @@ steps:
###########################################################
- id: 'npm-install'
name: 'node:16.14.0'
dir: 'point-of-sale-app/ui'
dir: 'src/ui'
entrypoint: 'npm'
args: [ 'install' ]
# indicates that the step need not wait for any other step
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@ target
test-server
test-server.yaml
dev.yaml
pos-quickstart.yaml

node
node_modules
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -17,4 +17,7 @@ If you’re using this app, please ★Star the repository to show your interest!

Edge computing is a distributed computing paradigm that brings computation and data storage closer to the location where the action is, to improve response times and save bandwidth. Multiple industries _(e.g. Retail, Telecommunication, Manufacturing and Energy)_ are facing a growing demand to provide localized, consistent, low latency services that expose compute services. Workloads range from order management, ML for images/traffic analysis/safety, device management like refrigeration, fryers, etc. [Anthos clusters on Bare Metal](https://cloud.google.com/anthos/clusters/docs/bare-metal) and [Anthos cluster on VMware](https://cloud.google.com/anthos/clusters/docs/on-prem) are unique solutions for deploying and managing workloads on clusters distributed across customer data centers and device fleets.

---

### Resources
- [Deploy the application to a cluster](/docs/quickstart.md) _(Quickstart)_
4 changes: 2 additions & 2 deletions anthos-baremetal-edge-deployment/README.md
Expand Up @@ -11,7 +11,7 @@ In the quick start guide that follows we _emulate_ nodes in an edge location
using **Google Compute Engine (GCE)** VMs and walkthrough a use-case for
installing **Anthos on Bare Metal (ABM)** in that edge location. The
installation process also installs **Anthos Config Management (ACM)** in the
Anthos on Bare Metal clusters. We then show how a [**Point-Of-Sales** application](/point-of-sale-app/)
Anthos on Bare Metal clusters. We then show how a [**Point-Of-Sales** application](https://github.com/GoogleCloudPlatform/point-of-sale)
is automatically deployed to this edge location by _syncing_ with the [configurations](acm-config-sink/)
found in this repository using **ACM**. Finally, we experiment by updating the
configurations in this repository to see the changes being adopted on the edge
Expand Down Expand Up @@ -47,7 +47,7 @@ _(including instructions for installing in an [Intel NUC](https://www.intel.com/
- **[Java](https://www.oracle.com/java/technologies/downloads/#java11)** [11.*] _(Optional)_

> _**Note:** The prerequisites marked as _(Optional)_ are only required if you
> want to modify the source for the [Point-Of-Sales](/point-of-sale-app)
> want to modify the source for the [Point-Of-Sales](https://github.com/GoogleCloudPlatform/point-of-sale)
> application. It is not required for just trying this Quick start._
---

Expand Down
Binary file added docs/images/pos.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions docs/quickstart.md
@@ -0,0 +1,84 @@
## Deploy the application to a cluster

### Prerequisites

- [gcloud CLI](https://cloud.google.com/sdk/docs/install)
- [kubectl CLI](https://kubernetes.io/docs/tasks/tools/)
- [skaffold CLI](https://skaffold.dev/docs/install/)

---

### Steps

1. **[Create a Google Cloud Platform project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project)**
or use an existing project. Set the `PROJECT_ID` environment variable and
ensure the Google Kubernetes Engine and Cloud Monitoring APIs are enabled.

```bash
export PROJECT_ID="<your-project-id>"
gcloud services enable \
container.googleapis.com \
monitoring.googleapis.com \
--project ${PROJECT_ID}
```
2. **Clone this repository.**
```bash
git clone https://github.com/GoogleCloudPlatform/point-of-sale.git
cd point-of-sale
Shabirmean marked this conversation as resolved.
Show resolved Hide resolved
```

3. **Create a GKE cluster.**
```bash
export CLUSTER_NAME=pos-cluster
export ZONE=us-central1-b
gcloud container clusters create $CLUSTER_NAME \
--project=${PROJECT_ID} \
--zone=${ZONE} \
--machine-type=e2-standard-2 \
--num-nodes=2
```

4. **Deploy the sample app to the cluster.**
```bash
# generate the release kubernetes manifests
skaffold render -p release > pos-quickstart.yaml

# apply the yaml files to the cluster
kubectl apply -f pos-quickstart.yaml
```

5. **Wait for the Pods to be ready.**
```bash
kubectl wait --for=condition=available --timeout=600s deployment --all
```

```bash
# expected output
+ kubectl wait --for=condition=available --timeout=600s deployment --all
deployment.apps/api-server condition met
deployment.apps/inventory condition met
deployment.apps/payments condition met
```

6. **Access the Point of Sale application** using the `EXTERNAL_IP` of the API
Server `Service`.
```bash
kubectl get service/api-server-lb -o jsonpath={'.status.loadBalancer.ingress[0].ip'}
```
```bash
# expected output (you will see a different IP address)
35.238.98.46
```
<p align="center">
<img src="images/pos.png">
</p>

> **Note**- you may see `<pending>` while GCP provisions the Loadbalancer. If
this happens, wait a few minutes and re-run the command.

7. [Optional] **Clean up**:
```bash
gcloud container clusters delete $CLUSTER_NAME \
--project=${PROJECT_ID} \
--zone=${ZONE}
```
74 changes: 74 additions & 0 deletions k8-manifests/README.md
@@ -0,0 +1,74 @@
# Kubernetes manifests

This directory holds the Kubernetes manifest files that can be used to deploy
the **Point-of-Sale** application. The manifests are seperated into categories
based on the deployment environment. You will notice multiple directories _(
e.g. `dev`, `release`)_ that contains the manifest files for the same Kubernetes
resources with minor differences according to the environment. The manifest
files for resources that does not change based on the environment are found at
the root of this _(`k8-manifests`)_ directory.

- [**dev** directory:](dev/)
- contains the manifest definition for the `Deployments` that can be used
during local development. These manifests are specific to the [**skaffold**](https://skaffold.dev/) tool. The container image
definitions ([1](dev/api-server.yaml#L33), [2](dev/inventory.yaml#L33)
, [3](dev/payments.yaml#L33)) in these files match the images defined in
the [**skaffold build context**](/skaffold.yaml#L55-L63)
of the `skaffold.yaml` file. This ensures, during the _dev flow_, skaffold
can push the images built from the locally available source to some
container-image repository _(
e.g. [Google Container Registry](https://cloud.google.com/container-registry)
,
[Google Artifact Registry](https://cloud.google.com/artifact-registry))_
and update the manifests to point to those freshly built images.
<br />
> **Note:** These manifests cannot be used with `kubectl` to directly apply to
> a cluster since they don't have a fully qualified URI for the
> container-images. You must use `skaffold` with the **dev** profile.

```shell
# Example with Google Container Registry
skaffold dev -p dev --default-repo gcr.io/<GOOGLE_CLOUD_PROJECT>

# Example with Google Artifact Registry
skaffold dev -p dev --default-repo us-docker.pkg.dev/<GOOGLE_CLOUD_PROJECT>/<IMAGE_REPO>
```

- [**release** directory:](release/)
- contains the manifests that use the
**latest released** images of the `Deployments`. The container image
definitions ([1](release/api-server.yaml#L34)
, [2](release/inventory.yaml#L34)
, [3](release/payments.yaml#L34)) in these files are pinned to the most
recent release tag. The release container-images are publicly accessible.
Thus, these manifests can be directly applied to any cluster
using `kubectl`.

```shell
# Example with kubctl
kubectl apply -f ./ # apply the common resources first
kubectl apply -f release/ # apply the Deployments next

# Example with skaffold
skaffold dev -p release # just point to the release profile
```

### Running with an embedded h2 database

The default deployment scenario for the application is to use a MySQL backend
that is running as a
separate [StatefulSet.](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/)
However, there can be scenarios where we want to deploy the application without
an external MySQL instance. To support such scenarios we have included a
separate mode where the applications can be started with an **embedded H2
database** that they connect to. This is enabled by an additional _skaffold
profile_ called **inmemory**. Switching this profile ON ensures that the MySQL
StatefulSets are not deployed and the application uses the embedded h2 database.

```shell
# Example with Google Container Registry
skaffold dev -p dev,inmemory --default-repo gcr.io/<GOOGLE_CLOUD_PROJECT>

# Example with Google Artifact Registry
skaffold dev -p dev,inmemory --default-repo us-docker.pkg.dev/<GOOGLE_CLOUD_PROJECT>/<IMAGE_REPO>
```
29 changes: 29 additions & 0 deletions k8-manifests/api-server-lb.yaml
@@ -0,0 +1,29 @@
# 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.

# [START anthosbaremetal_k8_manifests_api_server_lb_service_api_server_lb]
apiVersion: v1
kind: Service
metadata:
name: api-server-lb
spec:
type: LoadBalancer
selector:
app: api-server
ports:
- name: http
port: 80
targetPort: 8080
# [END anthosbaremetal_k8_manifests_api_server_lb_service_api_server_lb]
---
81 changes: 81 additions & 0 deletions k8-manifests/dev/api-server.yaml
@@ -0,0 +1,81 @@
# 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.

# [START anthosbaremetal_dev_api_server_deployment_api_server]
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-server
spec:
selector:
matchLabels:
app: api-server
template:
metadata:
labels:
app: api-server
spec:
serviceAccountName: default
terminationGracePeriodSeconds: 5
containers:
- name: api-server
image: api-server
env:
- name: INVENTORY_EP
valueFrom:
configMapKeyRef:
name: service-configs
key: INVENTORY_EP
- name: PAYMENTS_EP
valueFrom:
configMapKeyRef:
name: service-configs
key: PAYMENTS_EP
resources:
requests:
cpu: 100m
memory: 512Mi
limits:
cpu: 500m
memory: 1Gi
readinessProbe:
httpGet:
path: /api/ready
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
timeoutSeconds: 10
livenessProbe:
httpGet:
path: /api/healthy
port: 8080
initialDelaySeconds: 120
periodSeconds: 5
timeoutSeconds: 10
# [END anthosbaremetal_dev_api_server_deployment_api_server]
---
# [START anthosbaremetal_dev_api_server_service_api_server_svc]
apiVersion: v1
kind: Service
metadata:
name: api-server-svc
spec:
type: ClusterIP
selector:
app: api-server
ports:
- name: http
port: 8080
targetPort: 8080
# [END anthosbaremetal_dev_api_server_service_api_server_svc]