Introduction Kubernetes
Introduction Kubernetes
Introduction Kubernetes
Health Checks
Docker Swarm vs
Kubernetes
Docker Swarm vs Kubernetes
Docker Swarm vs Kubernetes
Faster when compared to Kubernetes Slower when compared with Docker Swarm
Not Reliable and has less features More Reliable and comparatively has more
features
Kubernetes Architecture
Kubernetes Architecture
Master Node
Controller Manager
API Server
Scheduler
Master Node Docker
It exposes the Kubernetes API. The Kubernetes API is the front-end for
Kubernetes Control Plane, and is used to deploy and execute all
etcd
operations in Kubernetes
API Server
Scheduler
Master Node Docker
The scheduler takes care of scheduling of all the processes, Dynamic Resource
Management and manages present and future events on the cluster
etcd
API Server
Scheduler
Master Node Docker
The controller manager, runs all the controllers on the Kubernetes Cluster.
Although each controller, is a separate process, but to reduce complexity,
all the controllers are compiled into a single process. They are as follows:
etcd Node Controller, Replication Controller, Endpoints Controller, Service
Accounts and Token Controllers
API Server
Scheduler
Master Node Docker
Kubelet takes the specification from the API server, and ensures the
application is running according to the specifications which were mentioned.
Each node has it’s kubelet service
Kubelet
Kubelet Kube-proxy
Kubernetes Architecture – Master Components
This proxy service runs on each node and helps in making services available
to the external host. It helps in connection forwarding to the correct
resources, it is also capable of doing primitive load balancing
Kubelet
Kubelet Kube-proxy
Kubernetes Installation
Kubernetes Installation
There are numerous ways to install Kubernetes, following are some of the popular ways:
Pod – Replica 1
Pod – Replica 2
Pod – Replica 1
Service
Pod – Replica 2
Pod – Replica 3
Working of Kubernetes
Pod – Replica 1
Image Processing
Service
Pod – Replica 2
Intellipaat.com/image
Pod – Replica 3
Ingress
Intellipaat.com/video
Pod – Replica 1
An Ingress is an object that allows access to
your Kubernetes services from outside the Service
Kubernetes cluster. You configure access by creating a Video Processing Pod – Replica 2
collection of rules that define which inbound
connections reach which services.
Pod – Replica 3
Deployments in Kubernetes
Deployments in Kubernetes
Deployment
Pods
YAML Syntax for Deployments
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
This YAML file will deploy 3 pods for nginx, and matchLabels:
maintain the desired state which is 3 pods, until app: nginx
template:
this deployment is deleted
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
Creating a Deployment
Once the file is created, to deploy this deployment use the following syntax:
Syntax
kubectl create –f nginx.yaml
List the Pods
To view the pods, type the following command:
Syntax
kubectl get po
As you can see, the number of pods are matching with the number of replicas specified in the deployment file
Creating a Service
Creating a Service
A Service is basically a round-robin load balancer for all the pods, which match with it’s name or selector. It
constantly monitors the pods, in case a pod gets unhealthy, the service will start deploying the traffic to the
other healthy pods.
Pod – Replica 1
Service
Pod – Replica 2
Pod – Replica 3
Service Types
LoadBalancer: Exposes the service externally using a cloud provider’s load balancer.
Pod – Replica 1
Service
Pod – Replica 2
Pod – Replica 3
Creating a NodePort Service
We can create a NodePort service using the following syntax:
Syntax
kubectl create service nodeport <name-of-service> --tcp=<port-of-service>:<port-of-container>
Creating a NodePort Service
To know the port, on which the service is being exposed type the following command:
Syntax
kubectl get svc nginx
Creating a NodePort Service
To know the port, on which the service is being exposed type the following command:
Syntax
kubectl get svc nginx
Creating an Ingress
What is an Ingress?
Kubernetes ingress is a collection of routing rules that govern how external users
access services running in a Kubernetes cluster.
Service
Intellipaat.com/image
Ingress
Intellipaat.com/video
Service
What is an Ingress?
Ingress Rules
Pod – Replica 1
Service
Pod – Replica 2
ClusterIP
Intellipaat.com/video
Pod – Replica 3
Ingress Ingress
Service Controller
Intellipaat.com/image
Pod – Replica 1
NodePort
Service
Pod – Replica 2
ClusterIP
Pod – Replica 3
Installing Ingress Controller
We will be using the nginx ingress controller, for our demo. We can download it from the following link:
Link
https://github.com/kubernetes/ingress-nginx/blob/master/docs/deploy/index.md
Define Ingress Rules
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: simple-fanout-example
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
The following rule, will redirect traffic which asks for spec:
/foo to nginx service. All the other requests, will be rules:
redirected to ingress controller’s default page - http:
paths:
- path: /foo
backend:
serviceName: nginx
servicePort: 80
Deploying Ingress Rules
To deploy the ingress rules, we use the following syntax:
Syntax
kubectl create –f ingress.yaml
Viewing Ingress Rules
To deploy the ingress rules, we use the following syntax:
Syntax
kubectl get ing
Kubernetes Dashboard
Kubernetes Dashboard
Dashboard is a web-based Kubernetes user interface. You can use Dashboard to deploy
containerized applications to a Kubernetes cluster, troubleshoot your containerized
application, and manage the cluster resources.
Installing Kubernetes Dashboard
To install Kubernetes Dashboard, execute the following command:
Syntax
kubectl create -f
https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-
dashboard.yaml
Accessing Kubernetes Dashboard
Change the service type for Kubernetes-Dashboard to Nodeport
Syntax
kubectl -n kube-system edit service kubernetes-dashboard
Logging into Kubernetes Dashboard
1. Check the NodePort from the kubernetes-dashboard service
2. Browse to your cluster on the internet browser, and enter the IP address
3. Click on Token, it will ask you for the token entry
4. Generate a token using the following command
$ echo $TOKEN