Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Kubernetes Getting Started

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Kubernetes getting started

https://youtu.be/d6WC5n9G_sM

bogdan stashchuk

What you’ll need for minikube

 2 CPUs or more
 2GB of free memory
 20GB of free disk space
 Internet connection
 Container or virtual machine manager, such as: Hyper-V,

choco install minikube


minikube start --driver=hyperv

docker fonctionne à l'intérieur des nodes minikube

quel ip address associé à un node ?

minikube ip

172.21.97.9

pour entrer à l'intérieur du node, la commande est:

ssh docker@172.21.97.9

yes

tcuser

quels sont les containers en cours d'exécution ?

docker ps
kubectl n'est pas disponible à l'intérieur d'un node

pour sortir, taper

exit

kubectl est disponible depuis notre ordinateur local

kubectl cluster-info

Kubernetes control plane is running at https://172.21.97.9:8443

CoreDNS is running at
https://172.21.97.9:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

on peut désormais créer deployment, services, ...

pour obtenir des nodes

kubectl get nodes

NAME STATUS ROLES AGE VERSION

minikube Ready control-plane 31m v1.24.3

quels sont les pods disponibles?

kubectl get pods

No resources found in default namespace.

Quels sont les namespaces

kubectl get namespace

NAME STATUS AGE


default Active 42m

kube-node-lease Active 42m

kube-public Active 42m

kube-system Active 42m

kubectl get pods --namespace=kube-system

NAME READY STATUS RESTARTS AGE

coredns-6d4b75cb6d-wt69g 1/1 Running 0 44m

etcd-minikube 1/1 Running 0 44m

kube-apiserver-minikube 1/1 Running 0 44m

kube-controller-manager-minikube 1/1 Running 0 44m

kube-proxy-7j9dp 1/1 Running 0 44m

kube-scheduler-minikube 1/1 Running 0 44m

storage-provisioner 1/1 Running 1 (44m ago) 44m

create pod manually

kubectl run nginx --image=nginx

pod/nginx created

kubectl get pods

NAME READY STATUS RESTARTS AGE

nginx 1/1 Running 0 71s

42:33

File is Ready to Download, Please Use Below


Password to Extract File
Password: 1234
https://www.bicfic.com/intellij-idea-crack-free-is-aeo/

https://pcsoftstore.com/intellij-idea-cracked-august-2022-version-download/

1:22

Introduction Stashchuk

Kuernetes allows you to create containers on differents servers physical or virtual, all of that
is done automatically without your intervention. You have just to tell kubernetes how many
containers you would like to create based on specific image.

K U B E R N E T E S = k8s

K8s takes care of automatic deployment across different servers located on physical or
virtual

Supported containers runtime: docker, crio, containerd

If you want to create deployment for your application inside the kubernetes cluster opened
to outside world, you could create load balancer ip address

Push image to docker hub


docker build . -t aunanant/k8s-web-hello
docker images | grep k8s-web

Grep is not part of the Windows operating system


docker login

Authenticating with existing credentials...

Login Succeeded

Logging in with your password grants your terminal complete access to your account.

For better security, log in with a limited-privilege personal access token. Learn more at
https://docs.docker.com/go/access-tokens/

docker push aunanant/k8s-web-hello

Using default tag: latest

The push refers to repository [docker.io/aunanant/k8s-web-hello]

92fcf09fbe1b: Pushed
d3dfad599d52: Pushed

baa77b9f25ff: Pushed

07f1e273e35f: Pushed

29ddfb506e6b: Mounted from library/node

1dd574bd2c87: Mounted from library/node

d101fffc6eaf: Mounted from library/node

994393dc58e7: Mounted from library/node

latest: digest:
sha256:95ccc5800c8da7b03aa3b3c77c36f94fbe7bd3a7dda2518b6d89b056bd06ca35 size:
1992

this image is public and you are able to utilize it in kubernetes deployment. We are able to
create Kubernetes deployment based on this image

kubectl get deploy


kubectl scale deployment k8s-web-hello --replicas=5

Unable to connect to the server: dial tcp 172.21.97.9:8443: connectex: A connection attempt
failed because the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond.

This problem occurs because of minikube. Restart minikube will solve this problem.Run
below command and it will work-

minikube stop
minikube delete
minikube start
minikube start --driver=hyperv

minikube stop

* Nœud d'arrêt "minikube" ...


* Mise hors tension du profil "minikube" via SSH…
E0901 03:31:23.916354 3948 main.go:130] libmachine: [stderr =====>] : Hyper-V\Stop-VM
: Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not
available.
At line:1 char:1
+ Hyper-V\Stop-VM minikube
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Stop-VM], VirtualizationException
+ FullyQualifiedErrorId :
InvalidOperation,Microsoft.HyperV.PowerShell.Commands.StopVM
* Nœud d'arrêt "minikube" ...
* 1 nœud arrêté.

minikube delete

* Nœud d'arrêt "minikube" ...


* Suppression de "minikube" dans hyperv...
* Le cluster "minikube" a été supprimé.

minikube start
minikube start --driver=hyperv

* minikube v1.26.1 sur Microsoft Windows 10 Pro 10.0.19044 Build 19044


* Choix automatique du pilote hyperv
* Démarrage du noeud de plan de contrôle minikube dans le cluster minikube
* Création de VM hyperv (CPUs=2, Mémoire=2200MB, Disque=20000MB)...
* Préparation de Kubernetes v1.24.3 sur Docker 20.10.17...
- Génération des certificats et des clés
- Démarrage du plan de contrôle ...
- Configuration des règles RBAC ...
* Vérification des composants Kubernetes...
- Utilisation de l'image gcr.io/k8s-minikube/storage-provisioner:v5
* Modules activés: storage-provisioner, default-storageclass
* Terminé ! kubectl est maintenant configuré pour utiliser "minikube" cluster et espace de
noms "default" par défaut.

kubectl get deploy

No resources found in default namespace.

kubectl get services

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE


kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13m

1:40:25

Let’s create deployment based on custom image

kubectl create deployment k8s-web-hello --image=aunanant/k8s-


web-hello

deployment.apps/k8s-web-hello created

kubectl get pods

NAME READY STATUS RESTARTS AGE


k8s-web-hello-5bc6dc48cf-rntxf 1/1 Running 0 31s

let’s create service using cluster ip

kubectl expose deployment k8s-web-hello --port=3000

service/k8s-web-hello exposed

kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

k8s-web-hello ClusterIP 10.106.129.58 <none> 3000/TCP 21s

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12h

let’s try to connect to this cluster ip

minikube ip

172.30.128.92

ssh docker@172.30.128.92

The authenticity of host '172.30.128.92 (172.30.128.92)' can't be established.

ECDSA key fingerprint is SHA256:6c3uKXpkvS7+yCgFk1AjNXZ5yX+GEslWd5Js4yM3AJk.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '172.30.128.92' (ECDSA) to the list of known hosts.

docker@172.30.128.92's password:tcuser

curl 10.106.129.58:3000

Hello from the k8s-web-hello-5bc6dc48cf-rntxf$

Let’s scale our deployment

1:48:51
let’s modify type of service which we created for our deployment

let’s delete the previous service

kubectl delete svc k8s-web-hello

service "k8s-web-hello" deleted

kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 19h

let’s create service again setting his type on nodeport

kubectl expose deployment k8s-web-hello --type=NodePort --


port=3000

service/k8s-web-hello exposed

kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

k8s-web-hello NodePort 10.105.186.88 <none> 3000:31837/TCP 94s

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 19h

Now, I’m able to connect to deployment using node ip address

I could get node ip address

minikube ip

172.30.128.92
I could take this ip and this port, and I would connect to one of the port, pasting this url on a
browser

http://172.30.128.92:31837

there is simple way to get url for this deployment, just typing

minikube service k8s-web-hello

|-----------|---------------|-------------|----------------------------|

| NAMESPACE | NAME | TARGET PORT | URL |

|-----------|---------------|-------------|----------------------------|

| default | k8s-web-hello | 3000 | http://172.30.128.92:31837 |

|-----------|---------------|-------------|----------------------------|

* Ouverture du service default/k8s-web-hello dans le navigateur par défaut...

minikube service k8s-web-hello --url

http://172.30.128.92:31837

let’s create a load balancer service

kubectl delete svc k8s-web-hello

service "k8s-web-hello" deleted

kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 20h

kubectl expose deployment k8s-web-hello --type=LoadBalancer --


port=3000

service/k8s-web-hello exposed

kubectl get svc


NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

k8s-web-hello LoadBalancer 10.104.11.185 <pending> 3000:31230/TCP 8s

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 20h

minikube service k8s-web-hello --url

http://172.30.128.92:31230

kubectl describe deploy k8s-web-hello

Name: k8s-web-hello

Namespace: default

CreationTimestamp: Thu, 01 Sep 2022 16:23:14 +0100

Labels: app=k8s-web-hello

Annotations: deployment.kubernetes.io/revision: 1

Selector: app=k8s-web-hello

Replicas: 4 desired | 4 updated | 4 total | 4 available | 0 unavailable

StrategyType: RollingUpdate

MinReadySeconds: 0

RollingUpdateStrategy: 25% max unavailable, 25% max surge

Pod Template:

Labels: app=k8s-web-hello

Containers:

k8s-web-hello:

Image: aunanant/k8s-web-hello

Port: <none>

Host Port: <none>

Environment: <none>

Mounts: <none>

Volumes: <none>

Conditions:

Type Status Reason


---- ------ ------

Progressing True NewReplicaSetAvailable

Available True MinimumReplicasAvailable

OldReplicaSets: <none>

NewReplicaSet: k8s-web-hello-5bc6dc48cf (4/4 replicas created)

Events: <none>

Let’s try to update version image of our deployment, RollingUpdate on passe d’une version à
une autre sans interruption

New pods will be created with new image, while old pods still running

Let’s go back to visual studio code

Build new image and after that push it

docker build . -t aunanant/k8s-web-hello:2.0.0

let’s push it to docker hub

docker push aunanant/k8s-web-hello:2.0.0

1:59:30
minikube ip

172.19.140.80

Dernière installation de minikube

Let’s set new image for deployment

kubectl set image deployment k8s-web-hello k8s-web-hello=aunanant/k8s-web-hello:2.0.0

deployment.apps/k8s-web-hello image updated

kubectl rollout status deploy k8s-web-hello

deployment "k8s-web-hello" successfully rolled out


new pods are created

kubectl get pods

NAME READY STATUS RESTARTS AGE

k8s-web-hello-647548f9f9-2x4ps 1/1 Running 0 6m43s

k8s-web-hello-647548f9f9-dqpj6 1/1 Running 0 6m43s

k8s-web-hello-647548f9f9-qhm4n 1/1 Running 0 6m35s

k8s-web-hello-647548f9f9-td969 1/1 Running 0 6m32s

k8s-web-hello-647548f9f9-z7t5d 1/1 Running 0 6m42s

kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

k8s-web-hello LoadBalancer 10.111.238.184 <pending> 3000:30599/TCP 46m

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 127m

declarative approach
2:10

delete all deployment and pods, services

kubectl delete all --all

pod "k8s-web-hello-647548f9f9-qzqh9" deleted

pod "k8s-web-hello-647548f9f9-t966t" deleted

pod "k8s-web-hello-647548f9f9-td969" deleted

pod "k8s-web-hello-647548f9f9-vtcrw" deleted

pod "k8s-web-hello-647548f9f9-wkbdf" deleted

service "k8s-web-hello" deleted

service "kubernetes" deleted

deployment.apps "k8s-web-hello" deleted

replicaset.apps "k8s-web-hello-5bc6dc48cf" deleted


let’s yaml files for deployment and service

type only Deploy and let vsc helps you

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: <Image>
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: <Port>

apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8s-web-hello
spec:
  selector:
    matchLabels:
      app: k8s-web-hello
  template:
    metadata:
      labels:
        app: k8s-web-hello
    spec:
      containers:
mink      - name: k8s-web-hello
        image: aunanant/k8s-web-hello
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 3000

PS C:\Users\jclon\k8s>
kubectl apply -f .\deployment.yaml

deployment.apps/k8s-web-hello created

kubectl get deploy

NAME READY UP-TO-DATE AVAILABLE AGE

k8s-web-hello 1/1 1 1 103s

kubectl get pods

NAME READY STATUS RESTARTS AGE

k8s-web-hello-cf4885679-2hhph 1/1 Running 0 2m13s

scale deployment and quantitis of replicas on yaml file

spec:
  replicas: 5
  selector:
    matchLabels:
      app: k8s-web-hello
  template:
    metadata:
      labels:
        app: k8s-web-hello

kubectl apply -f .\deployment.yaml

deployment.apps/k8s-web-hello configured

kubectl get pods

NAME READY STATUS RESTARTS AGE

k8s-web-hello-cf4885679-2hhph 1/1 Running 0 8m59s

k8s-web-hello-cf4885679-bxw5h 0/1 Pending 0 70s

k8s-web-hello-cf4885679-dttrd 0/1 Pending 0 70s

k8s-web-hello-cf4885679-ffcvj 1/1 Running 0 70s

k8s-web-hello-cf4885679-g92pn 0/1 Pending 0 70s


kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 33m

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
  - port: <Port>
    targetPort: <Target Port>

apiVersion: v1
kind: Service
metadata:
  name: k8s-web-hello
spec:
  type: LoadBalancer
  selector:
    app: k8s-web-hello
  ports:
  - port: 3030
    targetPort: 3000

kubectl apply -f .\service.yaml

service/k8s-web-hello created

kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

k8s-web-hello LoadBalancer 10.97.246.18 <pending> 3030:32720/TCP 48s

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42m


open connection to our deployment

minikube service k8s-web-hello

|-----------|---------------|-------------|----------------------------|

| NAMESPACE | NAME | TARGET PORT | URL |

|-----------|---------------|-------------|----------------------------|

| default | k8s-web-hello | 3030 | http://172.19.140.80:32720 |

|-----------|---------------|-------------|----------------------------|

🎉 Opening service default/k8s-web-hello in default browser...

Deleting deployment and service

kubectl delete all –all

pod "k8s-web-hello-cf4885679-dttrd" deleted

pod "k8s-web-hello-cf4885679-ffcvj" deleted

pod "k8s-web-hello-cf4885679-g92pn" deleted

service "k8s-web-hello" deleted

service "kubernetes" deleted

deployment.apps "k8s-web-hello" deleted

creating two deployments and connect them each other

Develop and Deploy Java, Spring Boot on Kubernetes with MySQL

https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/run-workshop?
p210_wid=3070&p210_wec=&session=1893876604080
3 Deploy SpringBoot with MySQL to Kubernetes (Minikube) –
Step by Step Tutorial
https://www.kindsonthegenius.com/deploy-springboot-with-mysql-to-kubernetes-
minikube-step-by-step-tutorial/

2 Deploy SpringBoot Application to Kubernetes(Minikube) Using


Deployment yaml file
https://www.kindsonthegenius.com/deploy-springboot-application-to-kubernetesminikube-
using-deployment-yaml-file/

1 Setup Kubernetes Locally – Deploy SpringBoot Application –


Step by Step Tutorial
https://www.kindsonthegenius.com/setup-kubernetes-locally-deploy-springboot-
application-step-by-step-tutorial/

You might also like