Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令

minute_5

关注

阅读 28

2023-12-28


Kubernetes from Zero to Hero

this blog is consists of topics within intro to K8s.

Welcome to learn k8s with me!!! [Kubernetes Crash Course for Absolute Beginners NEW] - YouTube


文章目录

  • Kubernetes from Zero to Hero
  • 0. What's K8s
  • 1. Kubernetes Architecture
  • 2. Main Kubernetes Components
  • 2.1 Node & Pod
  • 2.2 Service &Ingress
  • 2.3 ConfigMap & Secret
  • 2.4 Volume
  • 2.5 Deployment & StatefulSet
  • 3. Kubernetes Configuration
  • 4. Minikube & Kubeetcl - Setup k8s cluster locally
  • 4.1 MiniKube & Kubeetcl
  • 4.2 Deploy WebApp with MongoDB
  • 4.2.1 Demo Project Overview
  • 4.2.2 Create Config Files
  • 4.2.3 Deploy all resources in MiniKube cluster
  • 4.3 Interacting with K8s cluster
  • 5. Main Kubectl Commands


0. What’s K8s

a container orchestration tool.

  • Trend from Monolith to Microservices.
  • Increased usage of containers.
  • Demand for a proper way managing those hundreds of containers.

the rise of containers in microservices technology actually resulted in applications that are now comprised of hundreds or sometimes maybe thousands of containers.

Managing those loads of containers across multiple environments using scripts and self-made tools an be really complex and sometimes even impossible.

  • High Availability or no downtime
  • Scalability or high performance
  • Disaster recovery - backup and restore.

1. Kubernetes Architecture

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生

  • control node - several important processes
  • worker nodes

master nodes are much more important than worker nodes

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_02

2. Main Kubernetes Components

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_03

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_04

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_05

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_06

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_07

2.1 Node & Pod

Node: a virtual or physical machine

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_08

IP adjust every time the pod restart,so -> service

2.2 Service &Ingress

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_09

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_10

Ingress: cause the node-ip is not very practical.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_11

2.3 ConfigMap & Secret

change name: mogo-db-service -> mogo-db

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_12

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_13

! ConfigMap is for non-confidential data only! ->Secret

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_14

2.4 Volume

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_15

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_16

2.5 Deployment & StatefulSet

my-app died -> replicates everything!

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_17

Define blueprint for Pods: specify how many replicas you want to have

work with deployments instead of pods.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_18

! DB can’t be replicated via Deployment!

DB has state -> data inconsistence - > StatefulSet

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_19

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_20

however, deploying StatefulSet not easy -> common practice: DB hosted outside of k8s cluster.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_21

3. Kubernetes Configuration

talk to API server

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_22

C-M

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_23

each configuration file has 3 parts

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_24

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_25

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_26

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_27

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_28

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_29

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_30

4. Minikube & Kubeetcl - Setup k8s cluster locally

  • what’s MiniKube & Kubeetcl?
  • How to setup?

复查一下哪里出错了。

4.1 MiniKube & Kubeetcl

**MiniKube **

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_31

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_32

Master and Node processes run in ONE machine

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_33

Node: docker runtime pre-installed.

Kubeetcl: Command line tool for K8s cluster - interact

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_34

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_35

4.2 Deploy WebApp with MongoDB

4.2.1 Demo Project Overview

https://minikube.sigs.k8s.io/docs/start/

container or VM environment

本文参考环境:MacOS Sonoma 14.2

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_36

brew install hyperkit

Docker prefered!

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_37

minikube start --vm-driver docker

😑 翻墙也不行,miniKube FAQ已经为我们提供方法权限问题按提示修改即可。

minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_38

Or Start your cluster

minikube start --vm-driver=hyperkit

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_39

get status of nodes

kubectl get nodes

minikube status

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_40

4.2.2 Create Config Files

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_41

**MongoDB Endpoint **

  • mongo-config.yaml
  • mongo-secret.yaml

echo -n mogouser | base64
	echo -n mogopassword | base64

  • mongo.yaml - Deployment & Service in 1 file, because they belong together.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_42

  • label: for pods, label is a required field. for other compoments, it is optional.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_43

  • Selector: which Pods belong to Deployment?

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_44

  • Service: --- = you can have multiple YAML configurations within a file
    simple to keep port and target port the same.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_45

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_46

How do we pass these environment variables to mongo application?

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_47

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_48

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_49

same with password

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_50

similar with webapp:

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_51

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_52

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_53

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_54

Configure external Service

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_55

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_56

4.2.3 Deploy all resources in MiniKube cluster

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_57

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_58

4.3 Interacting with K8s cluster

get all components in cluster

kubectl get all

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_架构_59

kubectl get pod | configmap | secret

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_60

kubectl --help

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_61

kubectl get pod
	kubectle logs <podName>

Acess WebApp in Browser

kubectl get svc

minikube ip

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_62

不知道怎么回事,上面的不行,下面的行

minikube service webapp-service --url

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_63

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_64

5. Main Kubectl Commands

minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_65

kubectl create deployment nginx-delp --image=nginx

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_66

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_67

replicaset : a layer between deployment and pod.

kubectl get replicaset

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_68

Everything below Deployment is handled by k8s.

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_69

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_云原生_70

So let’s make a change. ->deployment

kubectl edit deployment nginx-depl

Auto-genetated configuration file with default values:

Debug pods

kubectl logs [pod-name]

Eg.

kubectl create deployment mongo-depl --image=mongo
kubectl get pod 

kubectl logs mongo-depl-558475c797-sb8nb

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_docker_71

kubectl describe pod [pod name]

好墨迹呀!!

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_72

Enter the container

kubectl exec -it [pod name] -- bin/bash

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_73

Delete deplyment & Apply configuration file

kubectl delete deployment [name]

Configuration files is a better way.

kubectl apply -f [file name]

Summarize

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_容器_74

Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令_kubernetes_75

https://www.youtube.com/watch?v=UPJpmOKGKzU

看完三小时的课程后,学习openFaas,部署k3s+openfaas


精彩评论(0)

0 0 举报