Below are the steps that we'll be using to deploy a complete web app. Note that this demo will deploy a broken application and we'll be fixing the Kubernetes yaml documents to make the deployment successful.
First we'll be:
- Deploying a new Namespace for our application
- Deploying a redis server into the new namespace
- Reviewing the objects that we've deployed with Kubernetes (Deployments, Pods)
- Getting Logs from the deployed resources via
kubectl
- Create namespace in Kubernetes
kubectl apply -f namespace.yml
Useskubectl
toapply
the file (-f
) with theNamespace
definition. Note that the namespace we're deploying into is defined in the yaml documents in01_redis/
.
- Deploy Redis Master and Replica
kubectl apply -f 01_redis/
Useskubectl
toapply
allyaml
definitions in the folder01_redis/
.kubectl get deployments
Gets thedeployment
resources from Kubernetes in thedefault
namespace. You will not see the redis deployments since we have deployed them to a different namespace.kubectl get pods
Gets the pods in thedefault
namespace. You won't see the redis pods since they've been created in another namespace.kubectl get --namespace k8s-workshop deployments,pods
Gets thedeployments
andpods
withkubectl
in thek8s-workshop
namespace. You should now see that adding--namespace k8s-workshop
will scope yourget
request to thek8s-workshop
namespace.kubectl describe --namespace k8s-workshop pod <pod name>
Describes the current state of the<pod name>
pod in Kubernetes. You can copy paste the name of the pod where you see<pod name>
.kubectl get --namespace k8s-workshop services
This lists all theservice
definitions in thek8s-workshop
namespace.kubectl logs --namespace k8s-workshop <pod name>
This prints the pods (containers)logs
to your terminal. You can paste any pod name in thek8s-workshop
namespace to replace<pod name>
.
We should now see a healthy Redis Master and Replica in the k8s-workshop
namespace in Kubernetes.
Next we'll be:
- Deploying the web app into the
default
namespace (A different namespace from the one we created above) - Watching the Cloud Load Balancer create external access to the web app
- CURLing the newly deployed web app to test manually
- Looking at the logs of the web app
- Fixing the broken web app deployment be deploying to the correct namespace
- CURL the web app again to test
- Deploy the basic webapp
kubectl apply -f 02_webapp/
This deploys all the yaml definitions in the02_webapp/
folder. Note that we are not defining the namespace in themetadata
of the yaml, so it will default to thedefault
namespace configured withkubectl
.kubectl get services
Gets all theservice
definitions in thedefault
namespace. We are going to wait untilExternal IP
has an IP Address.
- Test the web app
curl [external_ip]
This should show a hello world type response.curl [external_ip]/asdf/1234
When youcurl
this website, you should experience an error connecting to Redis.kubectl logs <webapp pod name>
Let's look at the errors in the logs from the pod... Cannot connect to redis because it's default namespace DNS resolution won't work from a different namespace.
- Fix the broken deployment
kubectl delete -f 02_webapp/
This will delete all the objects we created so that we can deploy correctly into thek8s-workshop
namespace.kubectl apply -f 02_webapp/ --namespace k8s-workshop
This overrides the unsetdefault
namespace and deploys all the yaml files into thek8s-workshop
namespace.kubectl get services --namespace k8s-workshop
We need to see the new service we've created, so the Load Balancer IP will have changed.
- Test the new deployment
curl [external_ip]/asdf/1234
Now we see that the web app correctly saves the key and value to the database.curl [external_ip]/asdf
We can also query the value from the database.
This section allows us to load test the web app and see the cluster responding by scaling the pod count up.
- Apply some load
./load.sh
- Open a new terminal or tab in your shell
- Look at the hpa occasionally to see the cpu usage go up
kubectl get hpa -n k8s-workshop
- The number of pods should scale up to meet the new demand
kubectl get deployment, po -n k8s-workshop
The 03_ingress
sub-directory contains an optional Ingress definition. The kubernetes.io/ingress.class
annotation may need to be changed to match that of your Ingress Controller. There is a second v1.18
yaml file for Kubernetes versions v1.18.0 and earlier, which do not support the networking.k8s.io/v1
APIVersion of Ingress.
Note that an Ingress Controller must be installed for Ingress resources to function. See the Ingress Nginx installation instructions for more information.