First deployment
This guide deploys a simple web server on your Kluster and exposes it on the Internet with a load balancer.
Prerequisites
- A Kluster with at least one workerpool, and
kubectlconfigured to access it. See Create a Kluster.
Deploy the application
Create a file hello.yaml containing a Deployment of two nginx replicas and a Service of type LoadBalancer:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
spec:
replicas: 2
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: nginx
image: nginx:stable
ports:
- containerPort: 80
resources:
requests:
cpu: 100m
memory: 64Mi
---
apiVersion: v1
kind: Service
metadata:
name: hello
spec:
type: LoadBalancer
selector:
app: hello
ports:
- port: 80
targetPort: 80
Apply it:
kubectl apply -f hello.yaml
Check that the pods are running:
kubectl get pods -l app=hello
NAME READY STATUS RESTARTS AGE
hello-6d8f7b9c5d-abcde 1/1 Running 0 20s
hello-6d8f7b9c5d-fghij 1/1 Running 0 20s
Access the application
The LoadBalancer Service automatically creates a load balancer with a public IP in your project. It can take a minute or two for the IP to be assigned:
kubectl get service hello --watch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello LoadBalancer 10.96.12.34 <pending> 80:31234/TCP 10s
hello LoadBalancer 10.96.12.34 195.15.x.x 80:31234/TCP 75s
Open http://<EXTERNAL-IP> in your browser, or:
curl http://<EXTERNAL-IP>
You should see the nginx welcome page.
Note
The load balancer and its public IP are billed according to standard Public Cloud pricing. They are deleted when the Service is deleted.
Storage and ingress
Persistent volumes are provided by Cinder (block storage). Two StorageClasses are available:
| StorageClass | When the PersistentVolumeClaim is deleted |
|---|---|
csi-cinder-sc-retain (default) |
The volume is kept, and still billed, until you delete it |
csi-cinder-sc-delete |
The volume is deleted |
Warning
With the default StorageClass, deleting a PersistentVolumeClaim does not delete the volume. Remove unused volumes in your project, or use storageClassName: csi-cinder-sc-delete for disposable data.
No ingress controller is installed. To serve several applications behind a single load balancer, install the ingress controller of your choice.
Clean up
kubectl delete -f hello.yaml
Next steps
- Use an ingress controller and cert-manager to serve several applications over HTTPS. See the Kubespray tutorial for an example setup.
- Give access to your team with OIDC authentication.