Containers and Kubernetes on IBM Cloud
Updated: 03 September 2023
Based on this Cognitive Class Learning Path
Prerequisites
Before getting started, you will need a few prerequisites
- IBM Cloud CLI
- Kubernetes Plugin
- Container Registry Plugin
- Kubernetes CLI
- Docker 1.9 or later
Kubernetes
Kubernetes is a container orchestrator to provision, manage and scale apps
It allows us to manage app resources, clusters, and infrastructure declaratively
Set Up and Deploy an App
# Push an Image to Registry
Note that the ng.bluemix.net
should be replaced with your API endpoint, for example in my case eu-gb.bluemix.net
, this is dependant on your Cloud Region
Clone the GitHub Repo and navigate into Lab 1
Then log into the IBM Cloud CLI with
Or, if using SSO
Next, log into the Cloud Registry with
Then create a namespace in the registry to store your images
And lastly build and push the docker image
Lastly we can make sure that our cluster is in a normal, operational state with
# Deploy Application
First we need to get our Kubernetes cluster configuration with
Once that has completed we will be faced with an option to set this config file as an environmental variable, we can copy this command and run it from Powershell to set the environmental variable, the resulting command will look something like the following for Windows
Next we can run our image as a deployment with
If after running that you are faced with an error which says error: failed to discover supported resources
it could be an indicator that the environmental variable did not set, in this case do the following
This will take some time, to view the status of our deployment we can use
When the status reads Running we can expose the deployment as a service which is accessed through the IP of the worker nodes, the HelloWorld example in this lab listens at 8080
We can examine our service with
We can get the public IP of our service with
We can visit our service/container from the
Visiting this via our browser should yield
Scale and Update Apps
# Scale Application with Replicas
We can view our deployment configuration file with
This will open a file that looks like this
From here change the spec.replicas
to 10
Then we can rollout our changes with
Once that is done we can view our pods with
Which should list our ten running pods
# Update and Rollback Apps
Kubernetes allows us to rollout app updates easily, and update the images on running pods, as well as rollback if issues are identified
Before we begin, we can get an image with a specific tag (in this case 1) and push it with
Thereafter we can make a change to our code and build the new docker image and push those to the cloud registry with a tag 2
Next, we can edit our config file with
Or we can edit the deployment with the command line with
If you see the following error on the Kubernetes Dashboard it may mean that you are using an incorrect registry endpoint in the last command, it is important to ensure that the registry endpoint is correct (as mentioned previously, in this case eu-gb
and not ng
)
Once we have updated our deployment configuration we can rollout our changes and check the status with one of the following commands
If we see that our deployments are not
Lastly we can do a rollout with
# Check Application Health
We can check app health periodically by using the healthcheck.yml
file, we can open this file with from our Lab 2
directory
We can edit this file as needed, by updating our image repository in this spec at
Then, while still in the Lab 2
directory, push this update with
Deploy an App with Watson Services
# Deploy the Watson App
Navigate to the Lab 3
Directory and build and push the Watson image to the Registry
Then do the same for the Watson Talk image
Next, in the watson-deployment.yml
file, update the registry information in the spec.containers
for the two containers
# Create Instance of Watson Service from CLI
We can create an instance of the Watson Tone Analyzer Service with
Where
tone_analyzer
is the service typestandard
is the plantone
is the service name
We can view that our service was created with
# Bind the Service to out Cluster
We can simply bind the service to our cluster with
And verify that it was created with
# Create Pods and Services
We can expose the secret to our pod so the service can be used by creating a secret data store as part of our deployment config, this is done already in the watson-deployment.yml
file
Then we can build the app in the Lab 3
directory with
We can verify that the Watson pods were created with
# Run the App and Service
We can explore the new objects we have created from the Kubernetes Dashboard or with the following commands
We can once again view our app by getting the public IP for the worker note with
We can run a get to our endpoint with a message
if we get a JSON output then we know the service and applications are running