/GoogleCloud_Sample11-Deploying-to-Google-Kubernetes-Engine-GKE

How to deploy Google Cloud Artifact Registry Docker Image to Google Kubernetes Engine (GKE)

Primary LanguageC#

How to deploy .NET8 WebAPI Docker Image stored in Google Cloud Artifact Registry to Google Kubernetes Engine (GKE)

To create and upload the .NET8 WebAPI Docker image to Google Cloud Artifact Registry repo, see this github repo:

https://github.com/luiscoco/GoogleCloud_Sample10-Artifact-Registry

1. Set up Google Cloud SDK

Make sure you have the Google Cloud SDK installed and initialized on your local machine

gcloud init

2. Authenticate with GCP

Use the gcloud auth login command to authenticate with Google Cloud

Configure Docker to use gcloud as a credential helper:

gcloud auth configure-docker

3. Pull the Docker Image from Artifact Registry

Navigate to Google Cloud Artifact Registry list

image

See the repos list

image

We click on our repo

image

Then we click on myimagename

image

We also the image

image

Finally we click on the Pull tab

image

We copy the command to authenticate and pull the image from the repo

image

gcloud auth configure-docker europe-southwest1-docker.pkg.dev
docker pull LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE:TAG

Replace LOCATION, PROJECT-ID, REPOSITORY, IMAGE, and TAG with your specific details

docker pull europe-southwest1-docker.pkg.dev/extreme-axon-381209/myfirstrepo/myimagename:v1.0

image

4. Set up your Kubernetes cluster

Search for GKE

image

Enable GKE API

image

If you haven't already, create a Kubernetes cluster in GKE

image

image

image

image

image

image

image

image

image

image

5. Configure kubectl to use your GKE cluster

We first follow the Kubectl authentication plugin installation instructions

We enter in this web page:

https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke

and we run this command:

gcloud components install gke-gcloud-auth-plugin

We configure the KBE cluster to use it

gcloud container clusters get-credentials autopilot-cluster-1 ^
--region europe-southwest1 ^
--project extreme-axon-381209

6. Deploy the image to GKE

You can use a Kubernetes deployment YAML file to deploy the image

image

deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-name
spec:
  replicas: 1
  selector:
    matchLabels:
      app: your-app
  template:
    metadata:
      labels:
        app: your-app
    spec:
      containers:
      - name: your-app
        image: europe-southwest1-docker.pkg.dev/extreme-axon-381209/myfirstrepo/myimagename:v1.0

service.yml

apiVersion: v1
kind: Service
metadata:
  name: your-app-service
spec:
  selector:
    app: your-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer

We can run these commands to apply the manifest files

kubectl apply -f deployment.yml
kubectl apply -f service.yml

7. Apply this configuration and very the running application

We run this command to apply the Kubernetes manifest file

kubectl apply -f deployment.yaml

Verify the Deployment: Check that your deployment is running as expected.

kubectl get deployments

We can verify the deployment and service data with the command:

kubectl get all

image

We can connect to the application with this URL: http://34.175.17.245/weatherforecast

image