Guestbook app deployed OpenShift and Kubernetes. IBM Final Project.
In this final project of Introduction to Containers w/ Docker, Kubernetes & OpenShift , you will build and deploy a simple guestbook application. The application consists of a web front end which will have a text input where you can enter any text and submit. For all of these we will create Kubernetes Deployments and Pods. Then we will apply Horizontal Pod Scaling to the Guestbook application and finally work on Rolling Updates and Rollbacks.
OpenShit/Istio · Docker · IBM Cloud · Kubernetes . DevOps
-
Complete the Dockerfile with the necessary Docker commands to build and push your image. The path to this file is
guestbook/v1/guestbook/Dockerfile
-
Export your namespace as an environment variable so that it can be used in subsequent commands.
-
Build the guestbook app using the Docker Build command.
-
Push the image to IBM Cloud Container Registry.
-
Verify that the image was pushed successfully.
-
Open the deployment.yml file in the v1/guestbook directory & view the code for the deployment of the application.
-
Apply the deployment using Kubernetes descriptive command from .yml file
-
Open a New Terminal and enter command to view your application.
-
Launch your application on port 3000.
-
Now you should be able to see your running application. Please copy the app URL which will be given.
-
Try out the guestbook by putting in a few entries. You should see them appear above the input box after you hit Submit.
-
FROM golang:1.15 as builder RUN go get github.com/codegangsta/negroni RUN go get github.com/gorilla/mux github.com/xyproto/simpleredis COPY main.go . RUN go build main.go FROM ubuntu:18.04 COPY --from=builder /go//main /app/guestbook COPY public/index.html /app/public/index.html COPY public/script.js /app/public/script.js COPY public/style.css /app/public/style.css COPY public/jquery.min.js /app/public/jquery.min.js WORKDIR /app CMD ["./guestbook"] EXPOSE 3000
-
export MY_NAMESPACE=sn-labs-$USERNAME
-
docker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v1
-
ibmcloud cr login ibmcloud cr region-set us-south docker push us.icr.io/$MY_NAMESPACE/guestbook:v1
-
ibmcloud cr images
- Autoscale the Guestbook deployment using
kubectl autoscale deployment
- Check the current status of the newly-made HorizontalPodAutoscaler
- Open another new terminal and enter command to generate load on the app to observe the autoscaling (Please ensure your port-forward command is running. In case you have stopped your application, please run the port-forward command to re-run the application at port 3000.)
- Run command to observe the replicas increase in accordance with the autoscaling.
- Run the above command again after 5-10 minutes and you will see an increase in the number of replicas which shows that your application has been autoscaled.
- Run command to observe the details of the horizontal pod autoscaler.
-
kubectl autoscale deploy guestbook --min=2 --max=10 --cpu-percent=10
-
kubectl get hpa guestbook
-
kubectl run -i --tty load-generator --rm --image=busybox:1.36.0 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- [<your app URL>](https://zakizaja-3000.theiaopenshift-0-labs-prod-theiaopenshift-4-tor01.proxy.cognitiveclass.ai/); done"
-
kubectl get hpa guestbook --watch
-
kubectl get hpa guestbook
- Please update the title and header in index.html to any other suitable title and header like Guestbook - v2 & Guestbook - v2.
- Update the values of the CPU in the deployment.yml to cpu: 5m and cpu: 2m
- Apply the changes to the deployment.yml file.
- Open a new terminal and run the port-forward command again to start the app.
- Launch your application on port 3000. Click on the Skills Network button on the right, it will open the “Skills Network Toolbox”. Then click the Other then Launch Application. From there you should be able to enter the port and launch.
- Run command to see the history of deployment rollouts.
- Run command to see the details of Revision of the deployment rollout.
- Run command to get the replica sets and observe the deployment which is being used now.
- Run command to undo the deploymnent and set it to Revision 1.
- Run command to get the replica sets after the Rollout has been undone. The deployment being used would have changed.
-
docker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v2 && docker push us.icr.io/$MY_NAMESPACE/guestbook:v2
change yml file resources limits cpu:5m and request:2m
-
kubectl apply -f deployment.yml
-
kubectl rollout history deployment/guestbook
-
kubectl rollout history deployments guestbook --revision=2
-
kubectl get rs
-
kubectl rollout undo deployment/guestbook --to-revision=1
-
kubectl get rs