What is kubernetes? and how do you deploy there?
Welcome back. In this video, we're going to take the Docker image we built previously and deploy it to Kubernetes in a cloud environment. Kubernetes is an open source platform designed to automate the deployment, scaling, and management of containerized applications - think of it as an orchestration tool that helps manage clusters of Docker containers. We'll deploy to Google Cloud Platform, which offers about $300 in free credits for new accounts - plenty for this exercise, but remember to clean up resources afterward to avoid unwanted charges.
Prerequisites include a GCP account, the Google Cloud CLI, and kubectl installed locally. After creating a project (e.g., "grpc-course"), we'll create a Kubernetes cluster with two nodes. The cluster creation takes about five minutes, and we can authenticate kubectl using gke gcloud auth plugin. Verify the connection with kubectl get nodes.
First, we create a namespace to divide cluster resources. Each Kubernetes manifest starts with an API version (v1) and specifies the kind of resource. For the namespace, we'll add metadata with a name and labels (e.g., app: test-grpc). Apply this with kubectl apply -f and set it as your default context using kubectl config set-context --current --namespace=test-grpc.
Before deploying our application, we need to create a secret for pulling images from our registry. Use kubectl create secret docker-registry with your GitHub username and token if you're using GitHub packages. This secret allows Kubernetes to authenticate with your container registry.
Next comes the Deployment resource, using apps/v1 API version. The deployment spec includes replicas (we'll use 2), selector matching labels, and a template for our pods. The container spec needs our image, ports (50051 for gRPC), and resource limits (100m CPU, 128Mi memory). For resource requests, we'll match our limits since it's a simple application.
When building on M1 Macs, we need to specify platform: linux/amd64 in our Dockerfile build to ensure compatibility. After rebuilding with the correct platform and pushing to our registry, apply the deployment manifest. Monitor pod status with kubectl get pods and check logs with kubectl logs if needed.
Finally, create a Service to expose our deployment. The service spec includes our port configuration (50051) and uses type: ClusterIP for internal cluster access. The selector should match our deployment labels to properly route traffic. After applying the service manifest, verify with kubectl get service.
To test our deployment, use kubectl port-forward service/test-grpc 50051:50051 to forward the service port to your local machine. Then run your gRPC client locally - it should connect through the port forward to your Kubernetes service. You'll see connection logs in the port-forward output confirming the traffic flow.
In the next video, we'll expose this service properly to the internet with a domain name instead of using port forwarding. This deployment model with multiple replicas gives us the foundation for a scalable, manageable gRPC service.