- Install kubectl: installation instructions for kubectl
- Install minikube: installation instructions for minikube
- Start the minikube cluster
minikube start --extra-config "apiserver.cors-allowed-origins=["http://boot.dev"]"
- Start the cluster dashboard:
minikube dashboard --port=63840
- Pull the SynergyChat Docker image
docker pull bootdotdev/synergychat
You're all set!
Let's deploy our SynergyChat docker image to our local k8s cluster:
kubectl create deployment synergychat-web --image=docker.io/bootdotdev/synergychat-web:latest
See whether the deployment was successful by running
kubectl get deployments
Resources inside of Kubernetes run on a private, isolated network. We'll need to do some port forwarding using kubectl
Get the name of the running pod:
kubectl get pods
NAME READY STATUS RESTARTS AGE
synergychat-web-76dd6b65c5-xx58s 1/1 Running 0 10m
Set up port forwarding:
kubectl port-forward synergychat-web-76dd6b65c5-xx58s 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
You should now be able to access the web server at http://localhost:8080
Minikube runs on a single node, but it can run multiple pods by changing the "replicas" option in your deployment config.
Edit the deployment config:
kubectl edit deployment synergychat-web
Under the spec
section, change the replicas
field from 1 -> 2
spec:
...
replicas: 2
...
You should now see two pods running:
kubectl get pods
NAME READY STATUS RESTARTS AGE
synergychat-web-76dd6b65c5-nblp6 1/1 Running 0 7s
synergychat-web-76dd6b65c5-xx58s 1/1 Running 0 33m
Create a Config Map that defines the API_PORT for our upcoming backend API deployment
kubectl deploy -f api-configmap.yaml
Create a new deployment for our backend API
kubectl apply -f api-deployment.yaml
Create a Config Map for our Crawler app
kubectl apply -f crawler-configmap.yaml
Create a Deployment for the Crawler app
kubectl apply -f crawler-deployment.yaml
Create Services for our Web, API, and Crawler Services provide a stable endpoint to reach our apps since Pod IP's are always changing
web-service.yaml
: Endpoint for clients to connect to the web serviceapi-service.yaml
: Endpoint for clients to access the APIcrawler-service.yaml
: Endpoint for our API to communicate with the crawler
Apply the configs to create the services:
kubectl apply -f web-service.yaml
kubectl apply -f api-service.yaml
kubectl apply -f crawler-service.yaml
Next we'll need to use the Gateway API to expose the services to the outside world
Install the Envoy Gateway
implementation of the Gateway API
kubectl apply --server-side -f https://github.com/envoyproxy/gateway/releases/download/v1.5.1/install.yaml
app-gatewayclass.yaml
creates a GatewayClass
that we can later use to create the actual Gateway. Every Gateway needs to be associated with a GatewayClass
app-gateway.yaml
creates the Gateway
itself
web-httproute.yaml
creates an HTTPRoute
that defines the routing rules for our Gateway to our web service
api-httproute.yaml
creates the same as above, but sets up routing rules for the API
In other words, any traffic to the synchat.internal
domain name should be routed to the web-service
and any traffic to synchatapi.internal
domain name should be routed to the api-service
Now we need to add the synchat.internal
and synchatapi.internal
domain names to our local machine
Add the following entries to /etc/hosts
127.0.0.1 synchat.internal
127.0.0.1 synchatapi.internal
Note: You also will need to add these to C:\Windows\System32\drivers\etc\hosts
in order to access them from Windows
Now we can create a tunnel which lets us access the Gateway from our external browser
minikube tunnel -c
Create a web-configmap.yaml
defining the WEB_PORT and API_URL env variables inside the Web Deployment
kubectl apply -f web-configmap.yaml
We also need to reference this configMap from web-deployment.yaml
# Under spec/containers
envFrom:
- configMapRef:
name: synergychat-web-configmap
Re-apply the changes to the Web Deployment
kubectl apply -f web-deployment.yaml
kubectl delete pod <pod_name>
kubectl logs <pod_name>