• Latest
  • Trending
Setup local Kubernetes cluster with Docker Desktop

Setup local Kubernetes cluster with Docker Desktop

June 23, 2022
Bolt Opens Africa Hub in Nairobi, Kenya

Bolt Opens Africa Hub in Nairobi, Kenya

July 6, 2022
Google Translate adds 10 new African languages

Google Translate adds 10 new African languages

July 6, 2022
Ericsson invites participants to its ‘Together Apart Hackathon’ in Nigeria

Ericsson invites participants to its ‘Together Apart Hackathon’ in Nigeria

July 6, 2022
Ghana GIPC And OT Sign MoU with America’s led black-owned tech business

Ghana GIPC And OT Sign MoU with America’s led black-owned tech business

July 6, 2022
Nigeria, Mozambique approve SpaceX Internet Deployment

Nigeria, Mozambique approve SpaceX Internet Deployment

July 6, 2022
IXAfrica to Build Africa’s Largest Hyperscale-Ready Datacentre in Nairobi

IXAfrica to Build Africa’s Largest Hyperscale-Ready Datacentre in Nairobi

July 6, 2022
Uganda to Launch its First Low Earth Orbit Satellite in September

Uganda to Launch its First Low Earth Orbit Satellite in September

July 6, 2022
Africa Data Centres to Build second 20MW Data Centre in Cape Town

Africa Data Centres to Build second 20MW Data Centre in Cape Town

July 6, 2022
Kingston Announces FURY Beast RGB DDR5 Memory

Kingston Announces FURY Beast RGB DDR5 Memory

July 6, 2022
Akasa Launches the DuoDock MX Dual NVMe Dock

Akasa Launches the DuoDock MX Dual NVMe Dock

July 6, 2022
Areca ARC-1686 Entry-Level NVMe Hardware RAID Adapters

Areca ARC-1686 Entry-Level NVMe Hardware RAID Adapters

July 6, 2022
TeamGroup Xtreem DDR4-4000 CL15 2x 16 GB

TeamGroup Xtreem DDR4-4000 CL15 2x 16 GB

July 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Wednesday, 6 July, 2022
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

Setup local Kubernetes cluster with Docker Desktop

by ITECHNEWS
June 23, 2022
in Data Science, Leading Stories
0 0
0
Setup local Kubernetes cluster with Docker Desktop

Learn how easy it is to deploy a container on your very own local kubernetes cluster, no need to worry about getting access to a Azure/AWS/GCP subscription. Just follow along.

Here are the Topics we will cover

YOU MAY ALSO LIKE

Bolt Opens Africa Hub in Nairobi, Kenya

Google Translate adds 10 new African languages

  1. Enable Kubernetes on DockerDesktop
  2. Deploy a “Hello World” app on your local cluster
  3. Deploy a NGINX app & access it from local browser using
  4. Port Forwarding

Pre-requisites:
DockerDesktop

Docker Desktop – Docker

MOST COMMON

favicondocker.com

NOTE: Docker Desktop Stable releases require the Hyper-V feature which is not available in the Windows 10 Home edition.


Enable Kubernetes Cluster on DockerDesktop
You can use other tools such as Minikube or Kind which are also suited for running a single Node Cluster locally.

First and foremost, Enable Kubernetes & Restart Docker Desktop

Docker Desktop

We now have a single-node cluster running on our systems, you can run kubectl commands and play around a bit before getting started.

On checking cluster-info shown below, we find that a master is running, now do remember that this is a single-node cluster i.e. master & worker are are on the same node. (A more practical use-case would have a master and many worker nodes to achieve High Availability-HA).

kubectl cluster info

kubectl get nodes

Check namespaces, not that it’s relevant in this context but remember we will be working in the default namespace.

kubectl get namespaces

Also, you will find a default ‘kubernetes’ service already running on clusterIP.


 

 


Deploy “Hello World” App on the Cluster
Lets start out by deploying a simple “Hello World” application. For this we will create a Deployment and a Service — which connects to the deployment.

Do remember that you can either run kubectl commands directly from a Power shell window or create manifest Yaml file(s) as shown below.

1. Deployment Creation
By creating a manifest file with kind: Deployment, we are essentially creating containers, pods, replicaSets in the background.

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  selector:
    matchLabels:
      app: hello
      version: 2.0.0
  replicas: 2
  template:
    metadata:
      labels:
        app: hello
        version: 2.0.0
    spec:
      containers:
      - name: hello
        image: "gcr.io/google-samples/hello-app:2.0"
        env:
        - name: "PORT"
          value: "50001"

_Translation:

Pull a container from gcr.io/google-samples/hello-app:2.0 and

replicas: 2 means that there will be 2 pods running any point of time._

2. Services — Access the deployment
service.yaml

apiVersion: v1
kind: Service
metadata:
  name: hello-service
spec:
  type: NodePort
  selector:
    app: hello
    version: 2.0.0
  ports:
  - name: http
    protocol: TCP
    port: 8081
    targetPort: 50001
    nodePort: 32000

Here the ‘hello-service’ connects to all the pods created above having name ‘hello’ as mentioned by the selector attribute at targetPort=50001

Remember, we are creating a NodePort service to enable access from outside the cluster. From within the cluster, all the pods are accessible through ClusterIP.

Hello World is deployed and is accessible through nodePort, http://localhost:32000/

Hello, world!
Version: 2.0.0
Hostname: hello-fdf67c7-b4fs4


Deploying Nginx in 3 steps

We will be deploying an nginx:alpine image (from the public docker hub registry) onto a local kubernetes cluster running on our DockerDesktop.

1. Create Deployment

Lets create nginx deployment, this will create a Deployment and a Pod

kubectl create deploy nginx —image=nginx:alpine

2. Create Service to expose deployment

We want our nginx app to be accessible from any pod within cluster, so we expose it.

kubectl expose deploy nginx --port=80 --target-port=8000

Verify if this nginx app is accessible from any other pod within the cluster, add a ubuntu test pod and run curl on the Pod IP

# lets connect to the nginx app using clusterIP
$ kubectl get service nginx
NAME    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
nginx   ClusterIP   10.106.163.0   <none>        80/TCP    25h
# spin up a test ubuntu pod
$ kubectl run -i --tty ubuntu --image=ubuntu --restart=Never -- sh
# check connectivity through PodIP and Port
$ curl http://10.1.0.13:80

BINGO !! we can reach the nginx deployment from within cluster

3. Access the deployment from outside the cluster (locally)

Now we want to make this nginx deployment accessible from outside the cluster.

Do remember that each Pod within a Cluster has a unique IP address, which can be accessed from outside the cluster through a Service, but if you are running cluster locally this can be easily achieved through Port Forwarding.

Port Forwarding will allow you to connect to a Pod on a forwarded(different) port from you local machine, without exposing the Services.

Use Port Forwarding to Access Applications in a Cluster | KubernetesUse Port Forwarding to Access Applications in a Cluster | Kubernetes

This page shows how to use kubectl port-forward to connect to a MongoDB server running in a Kubernetes cluster. This type of connection can be useful for database debugging. Before you begin You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts.

kubernetes.io

Lets port-forward our nginx deployment to a random port.

$ kubectl port-forward deployment/nginx :80
Forwarding from 127.0.0.1:56271 -> 80
Forwarding from [::1]:56271 -> 80
Handling connection for 56271
Handling connection for 56271
Handling connection for 56271
Handling connection for 56271

Open up your browser and point to the localhost:56271 (forwarded port)

Nginx Welcome Page

NOTE: Port-Forwarding need to be running all the time for this to work

Hope this blog helps you in getting started with kubernetes.

It’s an open ground, Play around !!

Source: Sayed Naweed Rizvi
Tags: Setup local Kubernetes cluster with Docker Desktop
ShareTweetShare
Plugin Install : Subscribe Push Notification need OneSignal plugin to be installed.

Search

No Result
View All Result

Recent News

Bolt Opens Africa Hub in Nairobi, Kenya

Bolt Opens Africa Hub in Nairobi, Kenya

July 6, 2022
Google Translate adds 10 new African languages

Google Translate adds 10 new African languages

July 6, 2022
Ericsson invites participants to its ‘Together Apart Hackathon’ in Nigeria

Ericsson invites participants to its ‘Together Apart Hackathon’ in Nigeria

July 6, 2022

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Bolt Opens Africa Hub in Nairobi, Kenya

Bolt Opens Africa Hub in Nairobi, Kenya

July 6, 2022
Google Translate adds 10 new African languages

Google Translate adds 10 new African languages

July 6, 2022

Recent News

  • Bolt Opens Africa Hub in Nairobi, Kenya July 6, 2022
  • Google Translate adds 10 new African languages July 6, 2022
  • Ericsson invites participants to its ‘Together Apart Hackathon’ in Nigeria July 6, 2022
  • Ghana GIPC And OT Sign MoU with America’s led black-owned tech business July 6, 2022
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© 2021 iTechNewsOnline.Com - Powered by BackUpDataSystems

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© 2021 iTechNewsOnline.Com - Powered by BackUpDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Go to mobile version