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
Make sure you have the Google Cloud SDK installed and initialized on your local machine
gcloud init
Use the gcloud auth login command to authenticate with Google Cloud
Configure Docker to use gcloud as a credential helper:
gcloud auth configure-docker
Navigate to Google Cloud Artifact Registry list
See the repos list
We click on our repo
Then we click on myimagename
We also the image
Finally we click on the Pull tab
We copy the command to authenticate and pull the image from the repo
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
Search for GKE
Enable GKE API
If you haven't already, create a Kubernetes cluster in GKE
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
You can use a Kubernetes deployment YAML file to deploy the 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
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
We can connect to the application with this URL: http://34.175.17.245/weatherforecast