In this post I deploy my scores-service container to the IBM Cloud Kubernetes service. This is not a blueprint for IBM Kubernetes deployments, if you looking for a blueprint, just take a look here. IBM Cloud documentation contains a great guide for getting started: How to setup and use IBM Cloud Kubernetes
I share my experiences and observations with you, along with my deployment.
Let’s start with an overview of the topics I touch in this blog post:
- Setting up the IBM Cloud Kubernetes service
- Pushing the local container image to IBM Cloud Container Registry
- Defining the Kubernetes deployment YAML to deploy the container
- Defining the Kubernetes service YAML for access the running Highscores-Service from the internet
The above picture shows a simplified architecture for the scores-service inside Kubernetes. You can see the relevant elements for the deployment. If you are interested in the details of these elements, just click on the linked Kubernetes documentation.
The major elements:
- Kubernetes in IBM Cloud
- Service inside Kubernetes is responsible for providing access to the scores-service over the internet, using a Loadbalancer
- Deployment is responsible for container deployment inside the Pod.
- Pod instantiation with the container image stored in the Container Registry
Setting up the IBM Cloud Kubernetes service
To setup the cluster, I follow the instruction in the IBM Cloud documentation and I choose an existing paid cluster.
Pushing the local container image to IBM Cloud Container Registry
To organize my scores-services images, I define a namespace called scores-services inside the IBM Cloud Container Registry. Maybe I will also create a container for the scores services UI in the future.
Now I push the container image into the IBM Cloud Container Registry, and I will use this image later in my deployment YAML. Therefore I use following push command:
docker push REGISTRY_NAME/NAMESPACE/IMAGE_NAME
docker push registry.eu-gb.bluemix.net/scores-services/scores-service:v1
Now I verify the result in the IBM Cloud Container Registry and you can see the uploaded container in the screenshot.
Defining the Kubernetes deployment YAML to deploy the Container
Now it is time to define the deployment yaml. The specifications for deployment yamls you can find in the kubernetes documentation. Usually the yaml configuration file contains specifications for deployments and services, but I want to separate these specifications into different files, to get an better overview and understanding. In the diagram you can see a simplified dependencies overview for deployment, pod, container, registry and port for deployment.
Let’s get started with the deployment yaml definition
apiVersion: apps/v1kind: Deployment metadata: name: scores-service labels: app: scores-service version: "1.0"
In the spec section, I give the container a name, and the information where the container image can be found in the Container Registry.
spec: containers: - name: scores-service image: "registry.eu-gb.bluemix.net/scores-services/scores-service:v1"
ports: - name: scores-http containerPort: 3000
Simplified I would say, labels are used in Kubernetes for the identification of elements like pods, for example.
This is full deployment yaml file:
apiVersion: apps/v1 kind: Deployment metadata: name: scores-service labels: app: scores-service version: "1.0" spec: replicas: 1 selector: matchLabels: app: scores-service template: metadata: labels: app: scores-service version: "1.0" spec: containers: - name: scores-service image: "registry.eu-gb.bluemix.net/scores-services/scores-service:v1" ports: - name: score-http containerPort: 3000
To deploy the scores-service in Kubernetes I execute the kubectl apply command .
I learned: this command is usually used for the creation of deployments or services, because it also updates an existing configuration in Kubernetes. Also this command can easily be reused for reapplying configurations in a terminal.
kubectl apply -f scores-services-deployment.yaml
The gif shows the deployment, using the command line and the verification of the deployment in the Kubernetes Dashboard . By the way, the dashboard was directly opened from the IBM Cloud UI.
Defining the Kubernetes service YAML for access the running Highscores-Service from the internet
The following diagram displays a simplified view of the dependencies related to the service, deployment, ports and labels.
Let’s get started with the service yaml definition
apiVersion: v1 kind: Service metadata: name: scores-service-lb labels: app: scores-service-lb
With the definition LoadBalancer, IBM Cloud Kubernetes creates an external LoadBalancer to provide access to the scores-service-lb and the service routes to the scores-service pod, which contains the container.
To ensure the right port of the container will be used, the selector and the targetPort defines which port is used for scores-service container in a pods. Port 80 defines the availability on the internet for scores-service-lb.
Note: With this background in mind, take a look at the diagram above again ;-).
apiVersion: v1 kind: Service metadata: name: scores-service-lb labels: app: scores-service-lb spec: type: LoadBalancer ports: - port: 80 targetPort: 3000 name: score-http selector: app: scores-service
Now I execute the kubectl apply command to deploy the scores-service-lb in IBM Kubernetes service.
kubectl apply -f scores-services-service-loadbalancer.yaml
The following gif shows the creation of the service in Kubernetes via the command line and the verification of the service instance in the Kubernetes Dashboard . Also tested in the gif is the access to the scores service UI from the internet is
Now the scores-service runs in Kubernetes and is available with the LoadBalancer IP address and the port 80.
Sample URL: http://loadblancer-ip-address:80
As you can see, my configuration is only for using HTTP to setup using HTTPS this will be another story.
I hope this was useful for you and let’s see what’s next?
#BlueCloudMirror, #Kubernetes, #Docker #Container, #IBMDeveloper