Deploy an Application
This tutorial describes how you can deploy a demo application to the cluster.
Requirements
- A working ingress controller and cert-manager as described in Create an Ingress Controller.
- A DNS record pointing to the external IP of the ingress controller.
Deploy an application
For this tutorial we are going the deploy the nginx hello image to our cluster. Therefor create a Deployment:
cat <<'EOF' | kubectl apply -f -
kind: Deployment
apiVersion: apps/v1
metadata:
name: nginx-hello
spec:
replicas: 3
selector:
matchLabels:
app: nginx-hello
template:
metadata:
labels:
app: nginx-hello
spec:
containers:
- name: nginx-hello
image: nginxdemos/hello:0.2
livenessProbe:
httpGet:
path: /
port: 80
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /
port: 80
timeoutSeconds: 1
EOF
Make the application accessible from the outside
In order to make the application accessible from the outside, we first have to expose it with a Service:
cat <<'EOF' | kubectl apply -f -
kind: Service
apiVersion: v1
metadata:
name: nginx-hello
spec:
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
selector:
app: nginx-hello
EOF
And then create an Ingress resource which registers it at our ingress controller and fetches a TLS certificate for it:
cat <<'EOF' | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-hello
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- nginx-hello.your-domain.com
secretName: nginx-hello-tls-secret
rules:
- host: nginx-hello.your-domain.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: nginx-hello
port:
number: 80
EOF