From the course: Docker for Developers: Create and Manage Docker Containers

Deploying a sample application

- [Instructor] Okay, we're almost ready to deploy our sample app to Kubernetes. Let's go through updating our image, applying our changes to Kubernetes, and viewing the result in minikube. First, let's rebuild the image we're using to make sure we have the latest version of our app. In the terminal, make sure you are in the root directory, and type docker build, then the -t flag. Tag the image with your docker hub username, then the name of the image, which is docker-demo, and version, which is version 3. Add the no-cache option, and use a period for the build context. If you see an invalid request error, delete the node_modules folder and try the command again. Once that's done, go ahead and push the image to your repo. Type docker push, and then the name and version of your image. Since we've changed the version of our image, we need to update it in app-deployment.yaml. Near the bottom of the file is where the image is specified. Go ahead and update it to version 3. Also update the image name with your username to match the image you just built. Next, let's create the my app namespace. Type kubectl apply, the -f flag, then the k8s folder, and namespace.yaml. You should see a message confirming that the namespace has been created. Now we can go ahead and create all deployments, services, and the persistent volume claim. Type kubectl apply, the -f flag, then the k8s folder, which is where our Kubernetes files are located. You should see a message saying that the app and db services and deployments have been created, as well as the PVC. There's also an error here, because Kubernetes is trying to access the compose file, which is not needed. Let's view the minikube dashboard to make sure everything is running. Type minikube dashboard. A browser should open, and go to the dashboard. In the namespace dropdown, select myapp. As you can see, everything is green, so our app should be up and running. To verify that everything is working, we need to get our app URL. Back in the terminal, open a new terminal window and type minikube service app, then the --url flag, followed by the -n flag and the namespace myapp. You should see a link in the output, so go ahead and click it. The message should be displayed, and you should be able to update it, verifying that the db connection works. If you encounter any errors, viewing the logs is your first line of defense. First, you need to get the name of the pod you want to view logs for. Back in the terminal, type kubectl get pods, the -n flag, and myapp. You should see the app and db pods listed here. Copy the name for the app pod. To view the logs, type kubectl logs, then paste the app pod name. Follow that with the -n flag and myapp. If everything is working properly, you should see a message saying that the server is listening on Port 3000. That's it. You've deployed a multi-container application to Kubernetes. Next, we'll discuss scaling.

Contents