This topic shows you how to install Cloud Service Mesh, which comes preinstalled
with an [Ingress Gateway](https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-control/).
With Cloud Service Mesh, you can configure a
[Kubernetes Ingress resource](https://kubernetes.io/docs/concepts/services-networking/ingress/)
for your Deployments if you need an
[Ingress controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/).
This topic provides an example that shows you how to configure a sample
Deployment and Ingress resource.

The installation of Cloud Service Mesh consists of two main parts:

1. Installing a specific version of the Cloud Service Mesh [customer-managed control plane](https://docs.cloud.google.com/service-mesh/docs/glossary#control_plane) and Ingress Gateway.
2. Labeling your namespaces with a [revision label](https://docs.cloud.google.com/service-mesh/docs/revisions-overview.md.txt) and redeploying your workloads to inject a [sidecar proxy](https://docs.cloud.google.com/service-mesh/docs/proxy-injection).

If you only need to use an Ingress object using an Ingress controller, you don't
have to inject a sidecar proxy into your workload Pods. But if you want the
[security benefits](https://docs.cloud.google.com/service-mesh/docs/overview.md.txt#security_benefits) that
Cloud Service Mesh provides, and if you want to make use of the
[traffic routing](https://docs.cloud.google.com/service-mesh/docs/overview.md.txt#traffic_management) capabilities,
you need to inject the sidecar proxies.

## Before you begin


Before you start using GKE on AWS, make sure you have performed the following tasks:

- Complete the [Prerequisites](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/prerequisites.md.txt).

<!-- -->

- Install a [management service](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management.md.txt).
- Create a [user cluster](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/creating-user-cluster.md.txt).
- Register your cluster with Connect by following the steps in [Connecting to your cluster with Cloud console](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/connecting-to-a-cluster.md.txt).
- Configure your cluster to [Use workload identity with Google Cloud](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/workload-identity-gcp.md.txt).
- If your user clusters have restricted outbound access to the internet,
  allow access to the following container repository domains:

  - `docker.io`
  - `quay.io`
- From your `anthos-aws` directory, use
  `anthos-gke` to switch context to your user cluster.

  ```sh
  cd anthos-aws
  env HTTPS_PROXY=http://localhost:8118 \
    anthos-gke aws clusters get-credentials CLUSTER_NAME
  ```
  Replace <var translate="no">CLUSTER_NAME</var> with your user cluster name.

  <br />

## Installing Anthos Service Mesh

Follow the steps in
[Install Cloud Service Mesh](https://docs.cloud.google.com/service-mesh/docs/unified-install/install).

## Creating an example Deployment

In this section, you install a sample application and create an Ingress endpoint
for it.

1. Create a Deployment of `hello-app` and a ClusterIP for the deployment.
   Copy the following YAML into a file named `hello-app.yaml`.

   ```yaml
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     labels:
       app: hello-app
     name: hello-app
   spec:
     selector:
       matchLabels:
         app: hello-app
     replicas: 3
     template:
       metadata:
         labels:
           app: hello-app
       spec:
         containers:
         - name: hello
           image: "gcr.io/google-samples/hello-app:2.0"
   ---
   apiVersion: v1
   kind: Service
   metadata:
     labels:
       app: hello-app
     name: hello-app
   spec:
     type: ClusterIP
     selector:
       app: hello-app
     ports:
     - protocol: TCP
       port: 8080
       targetPort: 8080
   ```
2. Apply the YAML to your cluster with `kubectl apply`.

   ```bash
   env HTTPS_PROXY=http://localhost:8118 \
     kubectl apply -f hello-app.yaml
   ```
3. Create a Kubernetes Ingress for the sample application. Copy the following
   YAML into a file named `hello-app-ingress.yaml`

   ```yaml
   apiVersion: networking.k8s.io/v1beta1
   kind: Ingress
   metadata:
     annotations:
       kubernetes.io/ingress.class: istio
     labels:
       app: hello-app
     name: hello-app
   spec:
     rules:
     - host:
       http:
         paths:
         - backend:
             serviceName: hello-app
             servicePort: 8080
   ```
4. Create the Ingress by applying the configuration with `kubectl apply`.

   ```bash
   env HTTPS_PROXY=http://localhost:8118 \
     kubectl apply -f hello-app-ingress.yaml
   ```
5. Check the status of your gateway with `kubectl get svc`.

   ```bash
   env HTTPS_PROXY=http://localhost:8118 \
     kubectl get ingress hello-app
   ```

   The `ADDRESS` field should have an ELB domain name. If the `ADDRESS`
   remains `pending`, confirm your VPC and Subnet labeling.
6. You can check the Ingress gateway URL by composing the host and port.
   To get your gateway URL, perform the following commands:

   ```bash
   export INGRESS_URL=$(env HTTPS_PROXY=http://localhost:8118 \
   kubectl get ingress hello-app -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
   echo "Your hello-app Ingress URL is: http://"$INGRESS_URL
   ```

   The last command prints the endpoint of your Ingress.
7. If you created a public Ingress, you can view the `hello-app` default web page
   in `curl` by visiting `http://$INGRESS_URL/`.

   ```bash
   curl $INGRESS_URL/
   ```

## Cleaning up

You remove the `hello-app` components with `kubectl delete`.

```bash
env HTTPS_PROXY=http://localhost:8118 \
  kubectl delete -f hello-app.yaml &&\
  kubectl delete -f hello-app-ingress.yaml
```

If you would like to remove Cloud Service Mesh, see
[Uninstalling Cloud Service Mesh](https://docs.cloud.google.com/service-mesh/docs/uninstall.md.txt#uninstalling).

## What's next

Learn more about:

- [Injecting sidecar proxies](https://docs.cloud.google.com/service-mesh/docs/proxy-injection)

- [Naming service ports](https://docs.cloud.google.com/service-mesh/docs/naming-service-ports)

- [Enabling Cloud Service Mesh optional features](https://docs.cloud.google.com/service-mesh/docs/enable-optional-features)

- [Integrating with third-party add-ons](https://docs.cloud.google.com/service-mesh/docs/third-party-integrations.md.txt)

- [Configuring the Ingress Gateway](https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-control/)

- [Routing traffic](https://istio.io/docs/tasks/traffic-management/ingress/)