kubernetes_start_tutorial_by_ruben_tejero.pdf

rubentejeroperez 7 views 11 slides Aug 16, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

tutorial de iniciacion a kubernetes
kubernetes start tutorial


Slide Content

Kubernetes
by Rubén Tejero Pérez

Container (Docker imagen)
DockerFile
FROM node:4.6
WORKDIR /app
ADD ./app
RUN npm install
EXPOSE 3000
CMD npm start

1º Create DockerFile

2º Build DockerFile for create a
Container with all info instruction runned
and data created
docker build .

3º Store & Share on DuckerHub
(Images Repository) (Optional)
docker login
docker push <name repo>

4º Run Container builded
docker run <name container>

Docker composer (optional)

Docke-composer.yml
web:
build: .
command: node index-db.js
ports:
- "3000:3000"
links:
- db
environment:
MYSQL_DATABASE: myapp
MYSQL_USER: myapp
MYSQL_PASSWORD: mysecurepass
MYSQL_HOST: db
db:
image: orchardup/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: myapp
MYSQL_USER: myapp
MYSQL_PASSWORD: mysecurepass
Is used for run multiple containers at the
same time in Docker and configure as
you want. Not used in Kubernetes

Kubernetes (How deploy your first Container)
Create a pod (pod-helloworld.yml)
apiVersion: v1
kind: Pod
metadata :
name : nodehelloworld.example.com
labels:
app: helloworld
spec:
containers:
-name: k8s-demo
image: wardviaene/k8s-demo
port:
-containerPort:30000

1º Create a Pod file referencing a container (pod.yml)

2º Create / registry the pod in kubectl
kubeclt create -f <pod file.yml>

Check it is working & config
·kubectl get pod
·kubectl describe pod <pod>
·kubectl expose pod <pod> -port=444 ---name=frontend
·kubectl port-forward <pod> 8080
·kubectl attach <podname> -i
·kubectl exec <pod> --command
·kubectl label pods <pod> mylabel=awesome
·kubectl run -i --tty busybox --image=busybox
--restart=Never -- sh

Load Balancer
Load Balancer (pod-service.yml)
apiVersion: v1
kind: Service
metadata :
name : nodehelloworld.service
spec:
ports:
-port:80
#nodePort:31001
targetPort:nodejs-port
protocol: TCP
selector:
app: helloworld
type:LoadBalancer #NodePort

Node Architecture
Node 1
Docker
iptables
kubelet
kube-proxy
pod 2
pod 1
c1
Node N
Docker
iptables
kubelet
kube-proxy
pod 2
pod 1
cn
.
.
.
c2
c3

Replica Controller
2º Create / registry the pod in kubectl
kubeclt create -f <rc file.yml>
Create a RC (rc.yml)
apiVersion: v1
kind: ReplicationController
metadata :
name : nodehelloworld.example.com
spec:
replicas:2
selector:
app:helloworld
templete:
metadata:
labels:
app:helloworld
spec:
containers:
-name: k8s-demo
image: wdwawddwa-demo
port:
- containerPort: 3000

Deployment
Specific tool for do deployments, You can do:

kubectl set deployments
kubectl get rs
kubectl get pods --show-labels
·Create a deployment
kubectl create -f <deployent.yml>
·Update a deployment
kubectl set image <dep-name> <img1>=<img2>
kubectl edit <dep-name>
·Rolling updates (0 s downtime)
kubectl rollout status <dep-name>
kubectl rollout history <dep-name>
·Rollback
kubectl rollout undo <dep-name> --to-revision=<n>
·Pause / Resume


#DEPLOYMENT
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-deployment
spec:
replicas: 3
selector:
matchLabels:
app: helloworld
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000

Service
Why use services in your app??

·A service is the logical bridge between the “mortal” pods
and other service or end-users.

·Pods are very dynamic, they come and go on the
kubernetes cluster
·Replication Controller pods are terminated and
created during scaling operations.
·When using Deployments, when updating the
image version, pods are terminated and new pods
take the place of older pods.
·That is why Pods should never be accessed directly, but
always through a Service



·When using the “kubectl expose” command earlier, you
created a new Service for your pod, so it could be
accessed externally

·Creating a service wil create an endpoint for your
pod(s):
·a ClusterIP: a virtual IP address only reachable from
within the cluster (this is the default)
· a NodePort: a port that is the same on each node that
is also reachable externally
·a LoadBalancer: a LoadBalancer created by the cloud
provider that will route external traffic to every node on
the NodePort (ELB on AWS)

Services Types
Node Port ClusterIP LoadBalancer
Used for share a Service with
out-side
An IP by Node same port

example:
Node 1 service-A:
1.10.2.1:30123
Node 2 service-A:
1.10.2.2:30123

Used for share a Service
with local Pods

A local IP and port




Used for share a Service
with local Pods

Join all the IPs Nodes
and expose like one

Service
·The options just shown only allow you to create
virtual IPs or Ports.

·There is also a possibility to use DNS names
·ExternalName can provide a DNS name for the
service
·e.g. or service discovery using DNS
·This only works when the DNS add-on is enabled
Service.yml
kind: Service
metadata:
name : helloworld-service
spec:
ports:
-port :31001
nodePort: 31001
targetPort: nodejs-port
protocol: TCP
selector:
app:helloworld
type: NodePort