{"id":20298462,"url":"https://github.com/j5py/containers","last_synced_at":"2025-05-07T20:34:38.410Z","repository":{"id":233017548,"uuid":"785792742","full_name":"j5py/containers","owner":"j5py","description":"Build a Web App using a Dockerfile, implement a Horizontal Pod Autoscaler, perform Rolling Updates and Rollbacks, and deploy from the OpenShift Internal Registry as the Final Project of Introduction to Containers w/ Docker, Kubernetes \u0026 OpenShift (from IBM on Coursera).","archived":true,"fork":false,"pushed_at":"2024-04-17T21:31:12.000Z","size":6860,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T06:12:31.906Z","etag":null,"topics":["cloud-native","containerization","docker","kubernetes","microservices","openshift","redis"],"latest_commit_sha":null,"homepage":"https://www.docker.com","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/j5py.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-12T16:26:45.000Z","updated_at":"2025-01-11T20:12:52.000Z","dependencies_parsed_at":"2024-04-15T23:44:15.800Z","dependency_job_id":null,"html_url":"https://github.com/j5py/containers","commit_stats":null,"previous_names":["j5py/containers"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j5py%2Fcontainers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j5py%2Fcontainers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j5py%2Fcontainers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j5py%2Fcontainers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j5py","download_url":"https://codeload.github.com/j5py/containers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252953718,"owners_count":21830891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-native","containerization","docker","kubernetes","microservices","openshift","redis"],"created_at":"2024-11-14T16:09:44.264Z","updated_at":"2025-05-07T20:34:36.568Z","avatar_url":"https://github.com/j5py.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n\n\n\n# Introduction to Containers with Docker, Kubernetes \u0026amp; OpenShift\n\u003e From IBM on Coursera\n\n\n\n## Peer-graded Assignment: Build and Deploy a Simple Guestbook\n\n\nResults available under [screenshots/assignment](https://github.com/j5py/containers/tree/main/screenshots/assignment) (file names imposed by the instructions)\n\n\n\n### Build the Guestbook app\n\nClone the git repository that contains the artifacts needed for this lab\n```\n[ ! -d 'guestbook' ] \u0026\u0026 git clone https://github.com/ibm-developer-skills-network/guestbook\n```\n\nChange to the directory for this lab\n```\ncd guestbook/v1/guestbook\n```\n\nComplete the Dockerfile ( [multi-stage builds](https://docs.docker.com/build/building/multi-stage/) ) with the necessary commands to build and push your image\n- The FROM instruction initializes a new build stage and specifies the base image that subsequent instructions will build upon\n- The COPY command enables us to copy files to our image\n- The ADD command is used to copy files/directories into a Docker image\n- The RUN instruction executes commands\n- The EXPOSE instruction exposes a particular port with a specified protocol inside a Docker container\n- The CMD instruction provides a default for executing a container, or in other words, an executable that should run in your container\n\n\nExport your namespace as an environment variable so that it can be used in subsequent commands\n```\nexport MY_NAMESPACE=sn-labs-$USERNAME\n```\n\nBuild the Guestbook app\n```\ndocker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v1\n```\n\nPush the image to IBM Cloud Container Registry\n```\ndocker push us.icr.io/$MY_NAMESPACE/guestbook:v1\n```\n\nVerify that the image was pushed successfully\n```\nibmcloud cr images\n```\n\nTo check your namespace\n```\nibmcloud cr namespaces\n```\n\nApply the Deployment\n```\nkubectl apply -f deployment.yml\n```\n\nTo view your app, open a new terminal\n```\nkubectl port-forward deployment.apps/guestbook 3000:3000\n```\n\nLaunch your app on port 3000 (Skills Network)\n\n\n\n### Autoscale the Guestbook app using Horizontal Pod Autoscaler\n\nAutoscale the Deployment\n```\nkubectl autoscale deployment guestbook --cpu-percent=5 --min=1 --max=10\n```\n\nYou can check the current status of the newly-made Horizontal Pod Autoscaler\n```\nkubectl get hpa guestbook\n```\n\nTo generate load on the app and observe the autoscaling, open another new terminal\n```\nkubectl run -i --tty load-generator --rm --image=busybox:1.36.0 --restart=Never -- /bin/sh -c \"while sleep 0.01; do wget -q -O- \u003cyour-app-url\u003e; done\"\n```\n\nTo observe the replicas increase in accordance with the autoscaling\n```\nkubectl get hpa guestbook --watch\n```\n\n\n\n### Perform rolling updates and rollbacks on the Guestbook app\n\nTo build and push your updated app image\n```\ndocker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v1 \u0026\u0026 docker push us.icr.io/$MY_NAMESPACE/guestbook:v1\n```\n\nApply other changes\n```\nkubectl apply -f deployment.yml\n```\n\nOpen a new terminal and run the port-forward command again to start the app\n```\nkubectl port-forward deployment.apps/guestbook 3000:3000\n```\n\nTo see the history of Deployment rollouts\n```\nkubectl rollout history deployment/guestbook\n```\n\nTo see the details of Revision of the Deployment rollout\n```\nkubectl rollout history deployments guestbook --revision=2\n```\n\nTo get the ReplicaSets and observe the Deployment which is being used now\n```\nkubectl get rs\n```\n\nTo undo the Deploymnent\n```\nkubectl rollout undo deployment/guestbook --to-revision=1 \u0026\u0026 kubectl get rs\n```\n\n\n\n\n## Optional: Deploy Guestbook App from the OpenShift Internal Registry\n\n\nResults available under [screenshots/optional](https://github.com/j5py/containers/tree/main/screenshots/optional)\n\n\n\n### Deploy\n\nCreate an ImageStream that points to your image in IBM Cloud Container Registry\n```\noc tag us.icr.io/$MY_NAMESPACE/guestbook:v1 guestbook:v1 --reference-policy=local --scheduled\n```\n\n1. Click on **Open OpenShift Console** under **Skills Network Toolbox**\n2. From **Developer** click **Add**, then  **Container image**\n3. Switch to **Image stream tag from internal registry**, then select your project\n4. Keep all the default values and hit **Create**\n5. From **Topology** click the `guestbook` Deployment, this should take you to the **Resources**\n    - Do not delete the `opensh.console` Deployment in **Topology** as this is essential for the OpenShift Console to function properly\n\n\n\n### Update\n\nLet’s update the Guestbook app and see how OpenShift’s image streams can help us update our apps with ease\n```\ndocker build . -t us.icr.io/$MY_NAMESPACE/guestbook:v1 \u0026\u0026 docker push us.icr.io/$MY_NAMESPACE/guestbook:v1\n```\n\n```\noc import-image guestbook:v1 --from=us.icr.io/$MY_NAMESPACE/guestbook:v1 --confirm\n```\n\nSwitch to **Administrator** \u003e **Builds** \u003e **ImageStreams** \u003e `guestbook` \u003e **History**\n\u003e View the guestbook in the browser again, OpenShift imported the new version of our image, and since the Deployment points to the image stream, it began running this new version as well\n\n\n\n### Storage\n\n**Topology** \u003e `guestbook-app` \u003e **Actions** \u003e **Delete application**\n\n```\ncd ../../v2\n```\n\nTo familiarize yourself with the Deployment configuration for the Redis master\n\u003e Redis is an open source, in-memory data structure store, used as a database, cache and message broker\n```\ncat redis-master-deployment.yaml\n```\n\nCreate the Redis master Deployment\n```\noc apply -f redis-master-deployment.yaml \u0026\u0026 oc get deployments\n```\n\nList Pods to see the Pod created by the Deployment.\n```\noc get pods\n```\n\nTo familiarize yourself with the Service configuration for the Redis master\n```\ncat redis-master-service.yaml\n```\n\nCreate the Redis master Service\n```\noc apply -f redis-master-service.yaml\n```\n\n**Developer** \u003e **Topology** \u003e `redis-master` \u003e **resources**\n\nTo familiarize yourself with the Deployment configuration for the Redis slave\n```\ncat redis-slave-deployment.yaml\n```\n\nCreate the Redis slave Deployment\n```\noc apply -f redis-slave-deployment.yaml \u0026\u0026 oc get deployments\n```\n\nList Pods to see the Pod created by the Deployment\n```\noc get pods\n```\n\nTo familiarize yourself with the Service configuration for the Redis slave\n```\ncat redis-slave-service.yaml\n```\n\nCreate the Redis slave Service\n```\noc apply -f redis-slave-service.yaml\n```\n\n**Developer** \u003e **Topology** \u003e `redis-slave` \u003e **resources**\n\nNow it’s time to deploy the second version of the Guestbook app, which will leverage Redis for persistent storage\n1. From **Developer** click **Add**, then **Import from Git**\n    - `https://github.com/ibm-developer-skills-network/guestbook`\n2. **Show advanced Git options**\n    - **Context dir** \u003e `/v2/guestbook`\n    - **Target port** \u003e `3000`\n\n\n**Developer** \u003e **Topology** \u003e `guestbook` \u003e **Routes**\n\n```\noc status\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj5py%2Fcontainers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj5py%2Fcontainers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj5py%2Fcontainers/lists"}