Deploying an application

Find out how to deploy a "Hello World" application

Last updated 21st September, 2021.

Objective

OVHcloud Managed Kubernetes service provides you Kubernetes clusters without the hassle of installing or operating them. This guide will explain how to deploy a simple Hello World application on a OVHcloud Managed Kubernetes cluster.

Requirements

  • an OVHcloud Managed Kubernetes cluster
  • at least one node on the cluster (see the ordering a node guide for details)
  • a well configured kubectl (see the configuring kubectl guide for details)

Instructions

Step 1 - Deploy your first application

The following command will deploy a simple application (nginx image) using a Kubernetes Deployment and a Kubernetes Service.

Create a hello.yml file for our ovhplatform/hello Docker image:

apiVersion: v1
kind: Service
metadata:
  name: hello-world
  labels:
    app: hello-world
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
  selector:
    app: hello-world
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world-deployment
  labels:
    app: hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: ovhplatform/hello
        ports:
        - containerPort: 80

And apply the file:

kubectl apply -f hello.yml -n default

After applying the YAML file, a new hello-world service and the corresponding hello-world-deployment deployment are created in the default namespace:

$ kubectl apply -f hello.yml -n default
service/hello-world created
deployment.apps/hello-world-deployment created

The application you have just deployed is a simple Nginx server with a single static Hello World page. Basically it just deploys the Docker image ovhplatform/hello

Step 2 - List the pods

You have just deployed a hello-world service in a pod in your worker node. Let's verify that everything is correct by listing the pods.

kubectl get pods -n default

You should see your newly created pod:

$ kubectl get pods -n default
NAME                                           READY     STATUS    RESTARTS   AGE
hello-world-deployment-d98c6464b-7jqvg         1/1       Running   0          47s

default namespace is the Kubernetes namespace by default so you don't need to specify it in your kubectl commands.

Step 3 - List the deployments

You can also verify the deployment is active:

kubectl get deploy -n default

And you will see the hello-service-deployment:

$ kubectl get deploy -n default
NAME                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-world-deployment        1         1         1            1           1m

Step 4 - List the services

And now you're going to use kubectl to see your service:

kubectl get services -n default -l app=hello-world

You should see your newly created service:

$ kubectl get services -n default -l app=hello-world
NAME          TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
hello-world   LoadBalancer   10.3.234.211   51.178.69.47   80:31885/TCP   6m54s

If under EXTERNAL-IP you get <pending>, don't worry, the provisioning of the LoadBalancer can take a minute or two, please try again in a few moments.

For each service you deploy with LoadBalancer type, you will get a new sub-domain XXXXXX.lb.c1.gra.k8s.ovh.net to access the service. In my example that URL to access the service would be http://6d6regsa9pc.lb.c1.gra.k8s.ovh.net

Step 5 - Test your service

If you point your web browser to the service URL, the hello-world service will answer you:

Testing your service

You can even test the newly created service, in command line, with curl:

curl 51.178.69.47

You should see your newly created service:

$ kubectl get services -n default -l app=hello-world
$ curl 51.178.69.47
<!doctype html>

<html>
<head>
<title>OVH K8S</title>
</head>
<style>
.title {
font-size: 3em;
padding: 2em;
text-align: center;
}
</style>
<body>
<div class="title">
<p>Hello from Kubernetes!</p>
<img src="./ovh.svg"/>
</div>
</body>
</html>

If you have an error message "Failed to connect to 51.178.69.47 port 80: Connection refused", it's normal. The service is starting, so you have to wait a few seconds in order to test it again.

Step 6 - Clean up

At the end you can proceed to clean up by deleting the service and the deployment.

Let's begin by deleting the service:

kubectl delete service hello-world -n default

If you list the services you will see that hello-world doesn't exist anymore:

$ kubectl delete service hello-world -n default
service "hello-world" deleted
$ kubectl get services -l app=hello-world
No resources found.

Then, you can delete the deployment:

kubectl delete deploy hello-world-deployment -n default

And now if you list you deployment you will find no resources:

$ kubectl delete deploy  hello-world-deployment -n default
deployment.extensions "hello-world-deployment" deleted
$ kubectl get deployments
No resources found.

If now you list the pods:

kubectl get pods -n default

you will see that the pod created for hello-world has been deleted too:

$ kubectl get pods -n default
No resources found

Go further

To learn more about using your Kubernetes cluster the practical way, we invite you to look at our OVHcloud Managed Kubernetes doc site.

Join our community of users.


Did you find this guide useful?

Please feel free to give any suggestions in order to improve this documentation.

Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.

Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.

Thank you. Your feedback has been received.


These guides might also interest you...

OVHcloud Community

Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Discuss with the OVHcloud community

In accordance with the 2006/112/CE Directive, modified on 01/01/2015, prices incl. VAT may vary according to the customer's country of residence
(by default, the prices displayed are inclusive of the UK VAT in force).