How to install Kubernetes locally via Docker
In this blog post, I’ll discuss the procedure of installing Kubernetes locally via Docker. I am now going to set up a simple,single node Kubernetes cluster using Docker.
Then you are almost ready to install Kubernetes. Final setup of this process is shown below.
There are three main steps in the process of installing Kubernetes locally via Docker.
Kubernetes has a simple Master-Minion architecture . Master provides all the Kubernetes infrastructure to manage containers. The master handles the APIs, scheduler and the replication controller.
Check the containers in your local host by executing the command : docker ps
Download the kubectl binary, which is a command line tool to interface with Kubernetes. For that enter the following command.
You may have to make it readable by
Then you can list the nodes in your cluster by executing the following command.
This should display the following.
First of all, we should make sure that we have installed Docker in our machine correctly. For that, If you need any help, refer this which is one of my previous blog posts that describes the procedure of installing Docker in a local machine.
Then you are almost ready to install Kubernetes. Final setup of this process is shown below.
As shown in the above figure, the final result is a single machine that will be both the master and the worker node. Etcd is used for storage. The final set up has some Kubernetes components like Kubernetes master, service proxy and kubelet. There are also some containers to run.
Step 1 : Run etcd
Use the following command to run the etcd. If etcd image does not exist in your local host, it will be downloaded from Docker Hub.
docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data
Kubernetes uses etcd to distribute information across the cluster by storing master state and configuration. Etcd is a key-value store designed for strong consistency and high-availability. The various master components watch this data and act accordingly. For example, starting a new container to maintain a desired number of replicas.
Step 2 : Run master
Then run the master. Similar to etcd, if master image does not exist in your local host, it will be downloaded from Docker Hub.
docker run \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
--volume=/dev:/dev \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
--pid=host \
--privileged=true \
-d \
gcr.io/google_containers/hyperkube:v1.1.1 \
/hyperkube kubelet --containerized --hostname-override="127.0.0.1" --address="0.0.0.0" --api-servers=http://localhost:8080 --config=/etc/kubernetes/manifests
Kubernetes has a simple Master-Minion architecture . Master provides all the Kubernetes infrastructure to manage containers. The master handles the APIs, scheduler and the replication controller.
- API Server: API server provides RESTful Kubernetes API to manage cluster configuration, backed by the etcd datastore.
- Scheduler: The scheduler determines what should run based on capacity and constraints. the replication controller ensures the right number of nodes have replicated pods. It places unscheduled pods on nodes according to labels.
- Controller Manager: This manages all cluster-level functions, including creating and updating endpoints, discovering nodes, managing and monitoring pods etc.
Step 3 : Run service proxy
Then run the service proxy. Similar to etcd and master, if image of service proxy does not exist in your local host, it will be downloaded from Docker Hub.
docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v1.1.1 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2
The service proxy is also known as the kube-proxy. It runs on each node and provides simple network proxy and load balancing capability. This service proxy enables services to be exposed with a stable network address and name. In brief, service proxy is a combination of load balancing and DNS service discovery that provides Kubernetes services which are collections of containers.
That’s it. At this point, you should have a running Kubernetes cluster. Let’s test it out.
Check the containers in your local host by executing the command : docker ps
We have actually started a kubelet which is responsible for managing all the containers. And its surface forms a variety of containers such as API server and scheduler as listed in the above container list.
Test it out
We can test the running Kubernetes cluster using kubelet binary.
$ wget
http://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl
http://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl
chmod a+x kubectl
./kubectl get nodes
This should display the following.
./kubectl run web --image=nginx
Run an application
./kubectl -s http://localhost:8080 run nginx --image=nginx --port=80
Executing docker ps will display you nginx running.
Expose it as a service
./kubectl expose rc nginx --port=80
Following command will show you the IP address of this service.
./kubectl get svc nginx --template={{.spec.clusterIP}}
Hit the web server with that IP address.
curl <insert-cluster-ip-here>
Pods are usually created using configuration artifacts. Here is an example of a pod configuration for the nginx pod. Create a file and save it as nginx-pod.yml.
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: web
spec:
containers:
- name: nginx
image: nginx
kind: Pod
metadata:
name: nginx
labels:
app: web
spec:
containers:
- name: nginx
image: nginx
Then execute the following command.
./kubectl create -f nginx-pod.yml
Kubernetes will pull the container image, start the container and register the pod. You can see the nginx pod running by the following command. Nginx container is now running in a pod.
./kubectl get pods
Each pod is assigned an IP address from an internal network for inter communication. These IP addresses are accessible locally.
wget <ip address of the nginx pod>
Nice informative post...Thanks for sharing.. Docker and Kubernetes Online Training in Hyderabad
ReplyDeleteThanks for sharing useful information about Docker and Kubernetes Training
ReplyDeleteDocker and Kubernetes Training
I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog.
ReplyDeleterpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
rpa course in bangalore
rpa training in chennai
rpa online training
Resources like the one you mentioned here will be very useful to me ! I will post a link to this page on my blog. I am sure my visitors will find that very useful
ReplyDeletepython training Course in chennai
python training in Bangalore
Python training institute in bangalore
This is such a good post. One of the best posts that I\'ve read in my whole life. I am so happy that you chose this day to give me this. Please, continue to give me such valuable posts. Cheers!
ReplyDeleteAWS Training in pune
AWS Online Training
This comment has been removed by the author.
ReplyDeleteReally nice article and thanks.
ReplyDeleteaws training in hyderabad
Excellent article about Java courses, I am happy to see your blogs.
ReplyDeleteDocker Container Courses
Really nice article and thanks
ReplyDeleteDocker and Kubernetes Training
Docker and Kubernetes Online Training
Docker and Kubernetes Training in Hyderabad
Kubernetes Online Training
Docker Online Training
Docker Training in Hyderabad
Docker Training
Kubernetes Training in Hyderabad
Informative blog
ReplyDeleteKubernetes Training in Hyderabad
The small live artificial intelligence empowered assistants like Google Assistant, Echo, Alexa, etc. are setting an example of an AI in the market. If you want to learn more about this topic, then you can read more about machine learning solutions.
ReplyDeleteI'm very happy to search out this information processing system. I would like to thank you for this fantastic read!!
ReplyDeleteDocker and Kubernetes Training
Kubernetes Online Training
Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time for more techniques
ReplyDeletekubernetes online training
kubernetes online course
kubernetes course
kubernetes training
Well written . keep sharing more and more DevOps Online Training
ReplyDeleteDevOps Online Training India
DevOps Online Training hyderabad
This is good information and really helpful for the people who need information about this.Nice article I was impressed by seeing this blog, it was very interesting and it is s for sharing all the information with us all.very useful for me.
ReplyDeleteSalesforce Training in Chennai
Salesforce Online Training in Chennai
Salesforce Training in Bangalore
Salesforce Training in Hyderabad
Salesforce training in ameerpet
Salesforce Training in Pune
Salesforce Online Training
Salesforce Training
ReplyDeleteThank you so much for the great article. It’s quite informative. We offer reviews of the best web hosting services available on the internet. We earn a bit of money from referring clients to the best web hosting platforms. Please note we only promote web hosting platforms we have utilized or have conducted a thorough research on.
Follow us at Best Web Host
Here is the best music to calm and relax your mind
ReplyDelete1. best relaxing music
2. best Depp sleep music
3. best meditation music
4. best calm music
5. best deep focus music
ReplyDeleteIt was a great information. Thanks for sharing.
CPQ Certification
CPQ Certification Salesforce
Thanks for sharing
ReplyDeleteOnline Training | Classroom | Virtual Classes
DevOps Training in Hyderabad with 100% placement assistance
1860 testers placed in 600 companies in last 8 years
Real time expert trainers
Indutry oriented training with corporate casestudies
Free Aptitude classes & Mock interviews
Very Nice Blog…Thanks for sharing this information with us. Here am sharing some information about training institute.
ReplyDeletetektutes tableautraining
Play With Kubernetes!
ReplyDelete~
Nanduni'S Tech Blog >>>>> Download Now
>>>>> Download Full
Play With Kubernetes!
~
Nanduni'S Tech Blog >>>>> Download LINK
>>>>> Download Now
Play With Kubernetes!
~
Nanduni'S Tech Blog >>>>> Download Full
>>>>> Download LINK
Play With Kubernetes!
ReplyDelete~
Nanduni'S Tech Blog >>>>> Download Now
>>>>> Download Full
Play With Kubernetes!
~
Nanduni'S Tech Blog >>>>> Download LINK
>>>>> Download Now
Play With Kubernetes!
~
Nanduni'S Tech Blog >>>>> Download Full
>>>>> Download LINK eQ
This is nice and more informative, Thank you for sharing it!
ReplyDeleteDevOps Training in Hyderabad with Placements
Nice Blog Keep Posting.
ReplyDeleteBest React-js Training institute in Hyderabad