Sunday, May 13, 2018

Learning Kubernetes 1. Running Minikube in a VirtualBox

Learning Kubernetes is an essential skill for DevOps engineers. My learning capability keep running with this daily dose!! :) I like the statement given in one of the author -Kubernetes is like captain of ship where multiple container clusters carried in the huge ship. This is a first step that will help you to enter into world of Kubernetes cluster technologies. Kubernetes is also known as k8s, this is quite young technology in the DevOps stack. Here we have two options to work-out on Learning Kubernetes:
  1. Kubernetes installing in master-slave in multiple nodes
  2. Minikube running locally single node
The first option will be used in real-time production environments, and the other is used for learning purpose. Here I've selected the second option for running WebLogic on Minikube.


Benefits of Kubernetes cluster

There are many benefits but in brief for WebLogic  

  • Kubernetes is the core component in Cloud Native Engineering platforms
  • Will be extensively used in aws, azur and BMC (Spartacus)
  • Ready to plug in real time web applications for easy deploy and scale
In this article I will be discussing about 
  1. How to prepare the VirtualBox for Minikube?
  2. Installation of Docker CE in Ubuntu
  3. Installation of Minikube in Ubuntu
  4. Deploy the minikube kubernetes dashboard
  5. Running WebLogic container in a pod

Prerequisites for Minikube in Ubuntu Virtual Box               

Install the VirtualBox if it was not latest and try to launch the new Ubuntu virtual disk image. I preferred to use Ubuntu 16.04 Xenial or Ubuntu 17.10 Artful are best suites for this experiment. Select the virtual disk from  uncompressed folder. Assigned the 4Gig Ram and 2 CPUs to the VirtualBox. Start the Ubuntu 16.04 VirtualBox image, after login osboxes user. Install the Guest Additions then try to configure shared folder where you wish to store the software that share between host machine with guest machine. Enable the shared clipboard -> bidirectional, and also drag and drop -> bidirectional.

1. Enter into a terminal use sudo -i to switch to root user, Update the apt package index with:

 apt-get update 

2. Install packages to allow apt to use a repository over HTTPS:
 
apt-get install \
                                apt-transport-https \
                                ca-certificates \
                                curl \
                                software-properties-common

3. Add Docker’s official GPG key:
 
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 

4. Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

 apt-key fingerprint 0EBFCD88
docker fingerprint validation in Ubuntu

Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well. To add the edge or test repository, add the word edge or test (or both) after the word stable in the commands below. 5. Adding repositories for the latest stable version

 add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) \
stable"

Note: Starting with Docker 17.06, stable releases are also pushed to the edge and test repositories. 6. Update the apt package index.

 apt-get update

7.Install the latest version of Docker CE, or go to the next step to install a specific version:

 apt-get install docker-ce 

8. login through root check below command if running or not:
 
                docker version
                docker info                
 

Install MiniKube 

Minikube is recommended for development environments or experience the Kubernetes in quick way in a local VM/Laptop. Docker swarm is also similar orchestration tool as Kubernetes. Kubernetes is opensource. Kubernetes is also support non-docker containers such as rocket containers.

1. Firstly, download minukube and kubectl

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Now kubectl download and move to /usr/local/bin
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && cp kubectl /usr/local/bin 

2. Set the MINIKUBE Env Variables
                export MINIKUBE_WANTUPDATENOTIFICATION=false
                export MINIKUBE_WANTREPORTERRORPROMPT=false
                export MINIKUBE_HOME=$HOME
                export CHANGE_MINIKUBE_NONE_USER=true
                mkdir $HOME/.kube || true
                touch $HOME/.kube/config
                export KUBECONFIG=$HOME/.kube/config

3. Lets start the Minikube with the none driver there are multiple drivers available. Each driver works according the platform where your host machine running. So using for this experiment vm-driver=none is best suitable because it is a Virtualization of Containerization.

minikube start --vm-driver=none

We can use kubectl commands which are able to interact with Minikube cluster. If you get any issue related to certs. The fix will be simply stop the minikube and start it.

Understanding kubernetes Head Node


 Minikube internally runs Kubernetes Head node or some other says that Master node, the whole control will be operated from this node only, which contains all components:

  1. etcd
  2. scheduler
  3. controller
  4. apiserver
  5. addons-manager
All the component required for Head node we can see in the namespace list:
kubectl get po --all-namespaces

Head node work with the set of namespaces

Kubelet is a Kubernetes Node agent which will be always running and monitoring all the components. If anything goes down it will brings up that component service automatically.

The etcd is capable to store the key, values which are used in the Kubernetes cluster. It is developed and inspired from coreos.

Every Kubernetes master will have scheduler, that is actually used to triggered as per the start time value, by default it will be 0.

Kuberneretes master have controller which internally talks to docker environment and a kubelet. Kubelet is like running an agent for Kubernetes master.The internal communication will be using RSA certs.

The apiserver in the master will be serving the client requests and they will be routed to the available Nodes. A Node may have multiple pods of same category.

Think Differently

Using minikube dashboard to deploy WebLogic Console application where many thousands of examples are there to tell hello-world app but say think differently web application that is WebLogic administration console as app to deploy as service and name it as wls-app.

Minikube Kubernetes will be providing us a nice UI dashboard to show the workload on the cluster. What all the status of pods, services, and also allows use to create and manage the deployments etc.

Lets start the dasshboard

minikube dashboard

when you run the above command it will try to launch the browser and start the dashboard
Minikube dashboard

Create a new deployment using dashboard

To create the new deployment in the minikube Kubernetes dashboard click on the 'deployments' under workload. On the top right select +CREATE  and there are :

  1. CREATE FROM TEXT INPUT
  2. CREATE FROM FILE
  3. CREATE AN APP
Select the third option

Minikube dash board deployment of WebLogic 
For the App Name, we’ll call this deployment 'wls-app'. Container image for WebLogic 12c we will take ismaleiva90/weblogic12:latest. Here I've used docker pull for this image once it is available in the local docker registry then we can proceed further above step.

To make a deployment complete we need to expose the container port to the host port.


kubectl expose deployment wls-app --port=7001 --type=NodePort

service "wls-app" exposed

kubectl get pods -o wide

kubectl get pods with wide option

kubectl get svc
Listing Kubernetes services with kubectl

It might take few secs to bring up the container in the pod. We can see that the pod is now Running and we will now be able to curl it/browse it:

minikube service wls-app


WebLogic Admin console running in a Kubernetes - local kube

6. if you want to delete wls-app and delete its deployment
kubectl delete service wls-app
service "wls-app" deleted


kubectl delete deployment wls-app
deployment "wls-app" deleted


7. Finally stopping the minikube

 minikube stop
Stopping local Kubernetes cluster...
Machine stopped.



Saturday, May 5, 2018

3. Learning How to build Best Docker images?

Containerization concept was available since 1978s in the UNIX. but the real usage and evaluation started from the year 2014 onward, a small community of docker open source organization started focus on it and developing it.

In the last post we had the un-official image then it went up the size up-to 3.8 GB. But same logic if we try on Oracle Linux 7-Slim version image it reduced 1 GB!!!

Use Layered approach for Oracle images

Most of the developers question how do we deliver it to end user when you create the containers for WebLogic. The best practice to use the layer approach for WebLogic applications. We have demonstrated with the following layer approach the whole stack is going to break down into two major parts:

  1. Read only 
  2. Read-write 
The latest image is on top which is only allow you to modify the content. where application jar/war/ear file will be deployed.
The bottom stack will be re-used by multiple developers to build their container and work with no-time spending that's the beauty of this contianerization technology.


Please refer to the Oracle White paper.
WebLogic docker image layers


Recently we had requirement to develop the containers of Oracle SOA. if we take the old stack it is not flexible enough to support the requirements. Always prefer to use the latest installers, Oracle SOA 12c is flexible for supporting Containerization.

Use the yum -y clean

When you install any of the dependent libraries that used for WebLogic or database or SOA software in the container. These libraries first pulled from the repo to a buffer, then installation process happen. Better to clean this junk after installation completed.

Preferable option to use official images
When you search for any image then you will be finding many images which are publicly available. Out of the images list there could be official select that one, which is more reliable than others.

Use Dockerfile to build images

Remember that in Dockerfile every instruction line is going to create a container. Each container will be stored in the docker engine just similar to the SVN repository that have id. To build docker image by write single RUN command with slash for separating commands for multiple commands to execute on temporary container.

Use docker-compose instead of lengthy docker run

using docker-compose you will be saving time to write lengthy  docker run commands. If you store the run command into compose file you will have more advantages you can build the docker image and also run the image as container in single go. You can modify the ports and other values to create more number of containers.

Multi purpose of docker-compose commands
Write your experiences/queries with the docker and docker-compose in the below give comment box. We are happy to help you in containerizing your environments.


References

Oracle WebLogic Server on Docker Containers

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6