Skip to content

Instantly share code, notes, and snippets.

@monodot
Last active January 4, 2021 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monodot/98a0dc7bb1ab231d3447ad416f62f95a to your computer and use it in GitHub Desktop.
Save monodot/98a0dc7bb1ab231d3447ad416f62f95a to your computer and use it in GitHub Desktop.
Deploy nginx on OpenShift - example

OpenShift Example: Deploy nginx web server by creating resources from YAML files

Let's deploy nginx!

We'll create a Deployment, a Service and a Route. 🥔🥔

  1. We create a Deployment to run the nginx-unprivileged image (this Nginx image doesn't run nginx as root - because OpenShift doesn't like that!)
  2. We create a Service which load balances between the pods in the Deployment.
  3. We create a Route which forwards traffic onto the Service, and the Pods!

Add each of these YAMLs to the cluster, using the web console or using oc apply -f <filename.yml>.

And.... VOILA.

Angela being fabulous

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginxinc/nginx-unprivileged:1.18
ports:
- containerPort: 8080
kind: Service
apiVersion: v1
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 8080
targetPort: 8080
kind: Route
apiVersion: route.openshift.io/v1
metadata:
name: nginx
spec:
to:
kind: Service
name: nginx
weight: 100
port:
targetPort: 8080
tls:
termination: edge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment