Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to host a static HTML website on Openshift

Sign upSign InSign upSign InHerman van der VeerFollowITNEXT--ListenShareIn this article series I’m going to show you how to create a proper Devops infrastructure on Redhat Openshift, an enterprise version of Kubernetes. We’ll start with one of the most basic things you can deploy on a cluster: a static HTML website. I’m writing this series because I had a hard time finding guides on how to work with Openshift, and the differences with Kubernetes are big enough that those guide don’t quite cut it.Prerequisites: an Openshift cluster, a container registry, PythonIn Kubernetes everything runs in a pod, which runs docker images. So to run a website, we have to package it into an image. For this we will use the popular web-server: Nginx.To create the HTML website itself we use the Python package mkdocs which will create a website from markdown files.md, and lastly to push changes to the md files to the website we'll set-up a deployment pipeline in Gitlab-ci. I will call the project "documentation", because that is what mkdocs is frequently used for. I use IBM Cloud, a less popular cloud provider but very similar to AWS.With mkdocs build you build the website, now copy the contents of your html website into a docker container:Then build the docker container and push it to the registry. To keep it relevant to enterprise solutions I put it in a private repository; that of IBM Cloud. This will create some extra work related to authentication.Give Openshift access to the registry through IAM:- Create a service-ID, Policy and API key on IBM Cloud- Add pull secret to Openshift- Create service account and add pull secret to itSee IBM docsNow we will start with creating files to configure the Openshift cluster. I would recommend saving them in a repository folder and applying them from there with the cli: oc apply -f filename.yaml. That way you have all your cluster configuration in one place, and you even have versioning though git. Working like this is called infrastructure as code (IaC). Because Openshift is more restrictive than Kubernetes, everything will be a bit harder.Below we will create the deployment file; this will retrieve the image we created, and run it in a pod on the cluster. Create the deployment with minimal rights (allowPrivilegeEscalation=false, runAsNonRoot: true, capabilities.drop), else Openshift will not allow it.Deploy the application:oc apply -f doc-deployment.yaml -n documentationYour nginx image is now running on Openshift!Now make it accessible to the outside world. You could do this through the CLI but I think it will be more informative and maintainable to do it with yaml files.CLI:#oc expose deployment documentation-page --port=80 --target-port=8080 --name=doc-route#oc get route doc-routeYaml:First you create a service that points to the app you just build.oc apply -f doc-service.yamlNow create a Route with an external web-address and point it to your service. In Kubernetes (K8s) you would create an Ingress here, but in Openshift you use the slightly different Routes.oc apply -f doc-route.yaml🎉 Tadaa! Your website is deployed on Openshift! 🎉By following these steps, you deployed your Docker container to an OpenShift cluster and made it publicly accessible through a route. Go to the address documentation.example.eu-de.containers.appdomain.cloud and if all went well you see your website!Next we will:2. Create a pipeline to automatically redeploy the website every time a change to the repository is made3. Add Single-Sign On authentication to the website----ITNEXTHerman van der VeerinITNEXT--Juntao QiuinITNEXT--10Daniel GlejznerinITNEXT--11Max Zimmermann 💡inITNEXT--3Atahan CeylaninYazılıma Dair--Love SharmainByteByteGo System Design Alliance--53Jacob BennettinLevel Up Coding--82The PyCoachinArtificial Corner--530Ignacio de Gregorio--11Gabriel Nascimento--HelpStatusWritersBlogCareersPrivacyTermsAboutText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

How to host a static HTML website on Openshift

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×