diff --git a/Usecases/Kubernetes Cluster/Readme.md b/Usecases/Kubernetes Cluster/Readme.md index 9c00a77..85aa0c9 100644 --- a/Usecases/Kubernetes Cluster/Readme.md +++ b/Usecases/Kubernetes Cluster/Readme.md @@ -1,3 +1,56 @@ # Use-Case - Build a Kubernetes Cluster -## Step-by-Step Instructions \ No newline at end of file +## Step-by-Step Instructions + +### Step-1 - Create a cluster in GKE Autopilot mode + +- In the Google Cloud Console, create a cluster on the **Kubernetes clusters** page +- Cluster basics: specify a name and region for the cluster, and use default values for other fields: + + ``` + name: ncar-autopilot-cluster-1 + region: us-central1 + ``` +- Networking: use default values and continue +- Advanced settings: use default values and continue + +### Step-1 (alternative) - Create a cluster from the command line +- Open a Google Cloud Shell terminal and run the following command + + ``` + gcloud container clusters create-auto "ncar-autopilot-cluster-1" \ + --project "i2class-fall2023-dmdevrie" \ + --region "us-central1" \ + --release-channel "regular" \ + --network "projects/i2class-fall2023-dmdevrie/global/networks/default" \ + --subnetwork "projects/i2class-fall2023-dmdevrie/regions/us-central1/subnetworks/default" \ + --cluster-ipv4-cidr "/17" + ``` + +### Step-2 - Add a deployment + +- From the **Kubernetes clusters** page, select `+DEPLOY` +- In addition to the nginx container, add the NCAR subsetting container. Select 'Add a container'. +- Choose `Existing container` and select the container `us-central1-docker.pkg.dev/i2class-fall2023-dmdevrie/ncar-transform/ncar-subset` from the Artifact Registry. +- Set the deployment name and app label (these should be the same): + + ``` + Deployment name: ncar-subset + Labels: { + app: ncar-subset + } + ``` + +### Updating the deployment +- Subsequent changes to the deployment can be made by modifying `deployment.yaml`. Open a Google Cloud Shell terminal and run the following command to apply the changes: + + First retrieve auth credentials for the cluster and verify + ``` + gcloud container clusters get-credentials ncar-autopilot-cluster-1 --zone=us-central1 + kubectl cluster-info + ``` + + Then apply the changes + ``` + kubectl apply -f deployment.yaml + ``` \ No newline at end of file diff --git a/Usecases/Kubernetes Cluster/deployment.yaml b/Usecases/Kubernetes Cluster/deployment.yaml new file mode 100644 index 0000000..c0c4e99 --- /dev/null +++ b/Usecases/Kubernetes Cluster/deployment.yaml @@ -0,0 +1,50 @@ +--- +apiVersion: "apps/v1" +kind: "Deployment" +metadata: + name: "ncar-subset-1" + namespace: "default" + labels: + app: "ncar-subset-1" +spec: + replicas: 3 + selector: + matchLabels: + app: "ncar-subset-1" + template: + metadata: + labels: + app: "ncar-subset-1" + spec: + containers: + - name: "nginx-1" + image: "nginx:latest" + - name: "docker-2" + image: "docker:latest" + - name: "ncar-subset-sha256-3" + image: "us-central1-docker.pkg.dev/i2class-fall2023-dmdevrie/ncar-transform/ncar-subset@sha256:7fcaf853a4262dc1f548d55a74753ac15a12a7a2490b1cd58cd24afb2bb4a0a2" + command: + - "docker run -t test-ncar-subset https://stratus.rda.ucar.edu/ds633.0/e5.oper.an.sfc/198010/e5.oper.an.sfc.128_167_2t.ll025sc.1980100100_1980103123.nc\ + \ 85 75 70 40 gs://ncar-subset-target/test-user-target/" +--- +apiVersion: "autoscaling/v2" +kind: "HorizontalPodAutoscaler" +metadata: + name: "ncar-subset-1-hpa-dtvf" + namespace: "default" + labels: + app: "ncar-subset-1" +spec: + scaleTargetRef: + kind: "Deployment" + name: "ncar-subset-1" + apiVersion: "apps/v1" + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: "Resource" + resource: + name: "cpu" + target: + type: "Utilization" + averageUtilization: 80