This week, we will take a look at Red Hat Container Development Kit (CDK). CDK provides a pre-built Container Development Environment based on Red Hat Enterprise Linux to help you develop container-based applications quickly. We will install CDK on a Windows machine and deploy our mykubernetesplanet Docker image from our last post to the Kubernetes cluster.
What is CDK?
As written in the introduction, CDK will provide us an environment in order to develop container-based applications. I jumped upon it during my search for information about Minikube and I wanted to try it out and see what CDK has to offer in comparison to Minikube for example.
CDK will create for you a VM running Red Hat Linux with Minishift. Minishift is a single-node OpenShift cluster (OpenShift is Red Hat’s Kubernetes platform). By the way, Minishift is a fork of Minikube. Also, a local Docker registry is available.
All information about CDK can be found at the homepage of CDK.
Installation of CDK
Complete installation instructions are available here. Although these instructions seem to be complete, I had the impression that quite some of the instructions were duplicate or didn’t need to be executed. I will therefore document the steps I had to take to install CDK on my Windows 10 machine and the problems I encountered.
First of all, installation needs to be done as an admin user, also the environment variables that need to be created, must be done as this same user.
In order to download Red Hat components, you can download the Red Hat Development Suite. You will need a Red Hat Developer account for this which you can create for free and use the Red Hat products for development purposes (you will need a paid license when you want to use the Red Hat products in a production environment of course).
With this Development Suite installer you can choose which Red Hat components you want to install. We will only check the following components:
- Red Hat Container Development Kit
- Cygwin (which is automatically checked when CDK is checked)
Beware that the installation will take up to 7GB of disk space.
You will also need a virtualization platform installed. I have already Hyper-V installed and this is also the default CDK is using. Next, you will need to set the env variable HYPERV_VIRTUAL_SWITCH to your external switch name of your Hyper-V settings (by means of the setx command). Beware to restart the console again, otherwise your env variable will have no value.
If you don’t have an external switch yet, you can do so via the Hyper-V Manager:
- Right-click your machine and choose Virtual Switch Manager…
- Create a New virtual network switch of type External
- Finally, you need to choose your External Network
Finally, you will have to add the Minishift executable to your user environment PATH variable.
In your installation directory, you will have the Minishift executable and the Cygwin tools. In your user home directory, a .minishift directory is added which contains an ISO file and a oc executable (The oc command line tool which is used for interacting with OpenShift clusters).
Start Minishift
Now that we have installed CDK, we can start Minishift as follows. Make sure to start the command from your C-drive, otherwise the path to the ISO file will not be found:
minishift start
This gives us the following error:
-- Starting Minishift VM .... FAIL E0519 13:22:20.319757 520 start.go:368] Error starting the VM: Error starting stopped host: exit status 1. Retrying. Error starting the VM: Error starting stopped host: exit status 1
I have not found out what the cause of this error was, but reading the installation instructions again, I executed the command:
minishift setup-cdk Running the Minishift start command brings us a bit further, but we run against this error: Error to register VM: ssh command error: command : sudo -E subscription-manager register --auto-attach --username user --password 'password' err : exit status 70 output : Registering to: subscription.rhsm.redhat.com:443/subscription You must first accept Red Hat's Terms and conditions. Please visit https://www.redhat.com/wapps/tnc/termsack?event[]=signIn . You may have to log out of and back into the Customer Portal in order to see the terms.
Let's go to the website in the error message, login with your Red Hat account and agree with the Terms and Conditions.
Stopping and starting Minishift still gives us an error:
-- Registering machine using subscription-manager Registration in progress .......... FAIL [20s] Error to register VM: ssh command error: command : sudo -E subscription-manager register --auto-attach --username user --password 'password' err : exit status 1 output : Development units may only be used on hosted servers and with orgs that have active subscriptions. Registering to: subscription.rhsm.redhat.com:443/subscription The system has been registered with ID: Installed Product Current Status: Product Name: Red Hat Enterprise Linux Server Status: Not Subscribed Unable to find available subscriptions for all your installed products.
Looking at the management page of my Red Hat account, I can not find anything that is wrong. I read somewhere that this can be due to some latency when subscriptions are added and subscriptions are made available to the tools. After approximately 1,5 hour I tried to start Minishift again, and then it suddenly worked.
Finally, run the following command to start the OpenShift Web Console in your browser:
minishift console
With user developer and any password, you enter the OpenShift Web Console.
If you encounter problems with starting Minishift, you can enable extra logging and probably you will see the cause of the problem:
minishift start --v=5 --show-libmachine-logs
Important notice before you continue
Before you continue, we have to do some extra configuration. It is needed because several days after I installed Minishift, I could not start Minishift anymore due to the following error:
Starting OpenShift using registry.access.redhat.com/openshift3/ose:v3.9.14 ... -- Starting OpenShift container ... Starting OpenShift using container 'origin' Waiting for API server to start listening FAIL Error: cannot access master readiness URL https://192.168.2.61:8443/healthz/ready Details: Last 10 lines of "origin" container log: I0527 13:31:12.241642 3334 logs.go:41] http: TLS handshake error from 192.168.2.60:65431: EOF I0527 13:31:12.301951 3334 logs.go:41] http: TLS handshake error from 192.168.2.60:65432: EOF I0527 13:31:12.302021 3334 logs.go:41] http: TLS handshake error from 127.0.0.1:43648: EOF I0527 13:31:12.309453 3334 logs.go:41] http: TLS handshake error from 127.0.0.1:43870: EOF I0527 13:31:12.638974 3334 logs.go:41] http: TLS handshake error from 127.0.0.1:43884: EOF I0527 13:31:13.227607 3334 logs.go:41] http: TLS handshake error from 127.0.0.1:43910: read tcp4 127.0.0.1:8443->127.0.0.1:43910: read: connection reset by peer I0527 13:31:13.252875 3334 cache.go:39] Caches are synced for APIServiceRegistrationController controller I0527 13:31:13.265697 3334 logs.go:41] http: TLS handshake error from 192.168.2.60:65435: remote error: tls: bad certificate I0527 13:31:13.305165 3334 cache.go:39] Caches are synced for AvailableConditionController controller I0527 13:31:13.325883 3334 cache.go:39] Caches are synced for autoregister controller Caused By: Error: Get https://192.168.2.61:8443/healthz/ready: x509: certificate is valid for 127.0.0.1, 172.17.0.1, 172.30.0.1, 192.168.2.58, not 192.168.2.61 Error during 'cluster up' execution: Error starting the cluster.
It seemed that the IP address of my VM had been changed and therefore Minishift won't start. See this issue. Luckily, there is a workaround for it. Stop Minishift and first set the following environment variable:
set MINISHIFT_ENABLE_EXPERIMENTAL=y
Then start Minishift again and after that, run the following command:
minishift ip --set-static
The output is as follows:
Writing current configuration for static assignment of IP address -- Set the following network settings to VM ... Device: eth0 IP Address: 192.168.2.61/24 Gateway: 192.168.2.254 Nameservers: 192.168.2.254 Network settings get applied to the instance on restart
This will prevent that the issue will pop again. Next, you will need to remove the OpenShift config:
minishift ssh -- "sudo rm -rf /var/lib/minishift/openshift.local.config"
Now, stop and start Minishift again. Unfortunately, I could not get any connection to OpenShift or the console and decided to delete the Minishift VM:
minishift delete
Next, I started Minishift anew. I also applied the --set-static command and restarted Minishift again. I hope this will prevent this error in the future and if you apply this before getting to work, you will not lose your work as I did.
Deploy Spring Boot Application
Let's check if we can deploy our Docker image from our Minikube post. We will need to follow these steps:
- Deploy our application in order that 1 Pod is created which runs our application;
- Create a Service in order to expose our application outside our Kubernetes cluster;
- In OpenShift, we also need to create a Route in order to be able to access our Service from our host machine;
- At the end, we will scale our application up to 2 Pods.
Deploy Application and create Pod
We click on our project in the OpenShift Web Console and select Deploy Image.
We fill in the Docker image name and tag we want to pull and click Deploy.
We receive a message that the image will be deployed.
When the Docker image has been pulled and deployed on a Pod, we will see the following in our overview page:
In the OpenShift Web Console, go to Applications - Pods and click on the Pod which has been created. You can see here the IP address which has been given to the Pod. Click the Terminal tab and enter the following command (of course, with the IP from your Pod):
curl http://172.17.0.3:8080/hello
This returns our hello message:
Hello Kubernetes! From host: mykubernetesplanet-1-kzsmj/172.17.0.3
Now we know that our application is deployed successfully.
Create the Service
In order to expose our application outside our Kubernetes cluster, we first need to create a Service. Go to Application - Services and choose Action - Import Yaml/JSON file. Enter the following:
apiVersion: v1 kind: Service metadata: name: mykubernetesplanet labels: app: mykubernetesplanet spec: type: NodePort ports: - port: 8080 nodePort: 31600 name: http selector: app: mykubernetesplanet
At this point, we can see the following information of our Service and we can see that a Pod is connected to our Service (due to the corresponding labels and selector of our Pod and Service).
Create the Route
Last step, is to create a Route. Go to Applications - Routes and click the Create Routes button. Fill in the following information:
After clicking the Create button, our Route is created:
Finally, it is time to check if we can access our hello url from our host machine. Go to the browser and enter the url http://mykubernetesplanet-myproject.192.168.2.58.nip.io/hello (the host name is retrieved from the Route).
Our browser shows us our hello message:
Hello Kubernetes! From host: mykubernetesplanet-1-kzsmj/172.17.0.3
Scale up to 2 Pods
Let's see if we can scale our Pods up to two. Go to Applications - Deployments. Click down to our Deployment and set the number of Replicas to 2 (you can also use the arrows next to the blue circle showing our Pod):
Automatically a second Pod is added.
Open a new incognito browser window and enter the url: http://mykubernetesplanet-myproject.192.168.2.58.nip.io/hello
Our browser now shows the host name of our second Pod.
Hello Kubernetes! From host: mykubernetesplanet-1-jv4h5/172.17.0.7
Summary
We installed the Container Development Kit of Red Hat and deployed our mykubernetesplanet Docker image to the Minishift Kubernetes cluster. Compared to Minikube, installation and deployment seemed to be a bit easier and faster to accomplish. On the other hand, the experience I gained with Minikube, helped me for getting up to speed with CDK. CDK is definitely something to look at.
The solution to connection refused issue, its not clear. Can you please help
LikeLike
If you have installed Minishift, the first thing you should do is:
* stop Minishift
* set the env variable: set MINISHIFT_ENABLE_EXPERIMENTAL=y
* start Minishift
* Execute the command: minishift ip –set-static
This way, you won’t run into the issue. Hope this clarifies it.
LikeLike