×
Community Blog Set up a Standalone Kubernetes Cluster with Minikube

Set up a Standalone Kubernetes Cluster with Minikube

In this tutorial, you will learn how to set up Minikube yourself, so that you can have a standalone Kubernetes cluster running locally.

By Umesh Kumhar, Alibaba Cloud Community Blog author.

Minikube is great tool for developers to setup a development environment through which they can fulfill almost all development and testing purposes from their own computer. Minikube runs a standalone cluster on a single virtual machine for a quick Kubernetes setup so that you can easily and quickly try your hands at deploying and testing Kubernetes on your own time.

In this tutorial, you will learn how to set up, install and configure Minikube yourself, so that you can have a standalone Kubernetes cluster running locally.

Prerequisites

For this tutorial, you'll need the following items:

  1. You'll need to have an Alibaba Cloud Elastic Compute Service (ECS) instance activated and have verified your valid payment method. If you are a new user, you can obtain a free account. If you don't know about how to set up your ECS instance, you can refer to this tutorial or this quick-start guide. As for the configuration, your ECS instance should have at least 1GB of RAM and a 1-Core processor.
  2. You have registered for a domain name from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain name server records.
  3. You have set up a sudo user

Also, for this tutorial, you'll want to make sure that virtualization is enabled on the Host OS, so that the host can create virtual machines.

Installing Minikube

To install Minikube, you'll also need to also install Kubectl, the KVM Driver and the Minikube cluster. You can follow these steps below to install all of them:

1.  Installing Kubectl

First, you'll want to install Kubectl. Kubectl will be the command line tool for your Kubernetes cluster. You'll use it to use to perform administrative operations on the cluster including deployment, scaling, and networking. Kubectl will also be helpful for you to obtain the status of your services or persistent volumes quickly. You can install Kubectl with the below commands:

curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/\
release/v1.3.0/bin/linux/amd64/kubectl

chmod +x kubectl 
 sudo mv kubectl /usr/bin/

After running the above commands, you can check by executing Kubectl, it will give you help of arguments to be provided.

2.  Install KVM Driver

Next, you'll want to install the KVM Driver. When it comes to installing the KVM driver, you'll want to make sure that your Host OS supports virtualization. Similarly, you'll want to make sure that VT-x/ AMD-V are enabled in BIOS (basic input/output system) setting of your OS. Also, if you're running KVM Driver in the VMware, then in the machine settings, you'll want to enable virtualization there too. By default, virtualization should be already enabled when it comes to your ECS instance on Alibaba Cloud.

sudo curl -L 
 https://github.com/dhiltgen/docker-machine-kvm/\
 releases/download/v0.7.0/docker-machine-driver-kvm \
 -o /usr/bin/docker-machine-driver-kvm
 
sudo chmod +x /usr/bin/docker-machine-driver-kvm

This will be used as core for the Minikube kubernetes cluster.

3.  Install Minikube

Now you'll want to install Minikube. The Minikube command line tool is used to setup the standalone cluster. The tool also provides many options for configuring the Kubernetes cluster environment, such as HTTP proxy options.

curl -Lo minikube https://storage.googleapis.com/minikube/\
releases/v0.6.0/minikube-linux-amd64 

 chmod +x minikube 
 sudo mv minikube /usr/bin/

4.  Install the Minikube Cluster.

When it comes to installing the Minikube cluster, the default VM driver to be used is Virtualbox. We can override this default value with any hypervisor such as KVM.

minikube start --vm-driver=kvm

Setting up your Kubernetes Cluster.

Now, let's set up a simple deployment using a basic hello Minikube image. In this example, we will be specifiying the Kubectl command line arguments as well as the YAML files to create deployment and service to expose the application.

1.  Deploying the Application

For this step, we will make a deployment of hello-minikube docker image using kubectl utility.Use kubectl command line to run the following:

kubectl run minikube-deployment \
--image=gcr.io/google_containers/echoserver:1.4 \
--port=8080

deployment "minikube-deployment" created

OR

Using YAML specification (deploy.yaml):

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minikube-deployment
  namespace: default
  labels:
    app:  minikube-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: minikube-deployment
  template:
    metadata:
      labels:
        app:  minikube-deployment
    spec:
      containers:
      - name: hello-container
        image: gcr.io/google_containers/echoserver:1.4
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
kubectl create –f deploy.yaml
deployment "minikube-deployment" created

2.  Expose the Application Service

Now to access the deployment outside of your minikube network, we need to expose the deployment as service so that we can access application. For this example, we will use the NodePort Service Type of Kubernetes, which will allocate a fixed port number ranges between 30000-32767 to the application pod.

Using kubectl command line:

 kubectl expose deployment minikube-service --type=NodePort

service "minikube-service" exposed

OR

Using YAML specification (service.yaml):

---
kind: Service
apiVersion: v1
metadata:
  name: minikube-service
  namespace: default
spec:
  selector:
    app: minikube-deployment
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: NodePort
kubectl create –f service.yaml
service "minikube-service" created

3.  Check Application Status

Now, you'll want to check your deployment pod status. You can do so with the following command:

 kubectl get pod

NAME                            READY     STATUS    RESTARTS   AGE
minikube-deployment-2423028-vddfw8   1/1       Running   0          4m

The output lists the pods running. You can check the status of these ports. If the status is ContainerCreating, then pod is in progress of being created. As such, you may need to wait several minutes for the process to complete. However, once the status is Running, then the pod is up and running.

To check your service is up and working properly, you can run the following command:

kubectl get svc

NAME                 CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
Minikube-service      10.0.0.23    <none>       8080:30341/TCP   4m

As you can see in output, the service is available with the assigned cluster IP address for internal communication between the service and deployment pods. Also under Ports, you can check if 8080 is mapped with 30341 port of the host machine. To do that, you can open the application using host machine IP address. Next, you can obtain the service URL to open the application by running the following command:

minikube service minikube-service --url

http://192.168.12.100:30341

Some Additional Minikube Commands

1.  You can easily deploy the Kubernetes dashboard using the minikube dashboard command. Alternatively, you can access the Kubernetes dashboard with your browser through using the console.

1

2.  To start another Minikube cluster, you can run the minikube -p cluster2 command. You can also launch a new cluster with different profile using –p parameter.

3.  To stop Minikube cluster you can run the following command. By using this command, you can stop the Minikuber cluster but still preserve the state of resources so that you can start virtual machine again with same resources.

minikube stop
Stopping local Kubernetes cluster...
Stopping "minikubeVM"...

4.  To restore the cluster, you can run the minikube start --vm-driver=kvm command.

5.  To delete the cluster, you can run the minikube delete command.This will completely delete the cluster with virtual machine and its resources.

6.  To obtain list of options, you can run the minikube help command.

Some Additional Minikube Commands

In this tutorial, you have learned how to set up Minikube yourself, so that you can have a standalone Kubernetes cluster running locally. Note that the Minikube standalone kubernetes cluster that you have set up on a single host, generally speaking, is not recommended to be used as a production cluster. For a production environment you would need some additional resources. Rather, this set up you made is more suited for development and testing purposes. For production, you can check out other tools such as kubeadm, that is used for simply installation of kubernetes cluster on public clouds, private clouds, on-premises machines.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments