LoadBalancer Service
As Deployment resources took care of deployments for us. Service resource will take care of serving the application to connections from outside of the cluster.
Requirements:#
- You have an account on Cloudify.ro *Register
- You have created a Cloudify.ro Kubernetes Cluster *Create Cluster
- You have downloaded the corresponding kubeconfig file and kubectl is working *Authentication
Deploy an Application#
The deployment is an alpine-test image.
$ kubectl apply -f deployment.ymlapiVersion: apps/v1kind: Deploymentmetadata: name: hostname-echo-deploymentspec: replicas: 1 selector: matchLabels: app: hostname-echo template: metadata: labels: app: hostname-echo spec: containers: - image: "lingxiankong/alpine-test" imagePullPolicy: Always name: hostname-echo-container ports: - containerPort: 8080$ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGEhostname-echo-deployment 1/1 1 1 41sDeploy LoadBalancer Service#
$ kubectl apply -f service.ymlapiVersion: v1kind: Servicemetadata: name: hostname-echo-svcspec: ports: - port: 8080 protocol: TCP targetPort: 8080 selector: app: hostname-echo type: LoadBalancer
The output should show:
$ kubectl get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEhostname-echo-svc LoadBalancer 10.254.172.232 <floating-ip> 8080:31521/TCP 5m12s`In your Cloudify.ro account will be added an Octavia LoadBalancer for Kubernetes LoadBalancer Service and a floating IP for external IP.
Test the connection:#
$ curl <floating-ip>:8080hostname-echo-deployment-5b4b888787-mmlkg