Kubernetes 从入门到实战 (feel more confident with me~ 进阶教程敬请期待!!) - k8s 架构及组件 | minikube实战 | kubectl指令
!
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
文章目录
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
-
control node - several important processes
-
worker nodes
master nodes are much more important than worker nodes
2. Main Kubernetes Components
2.1 Node & Pod
Node: a virtual or physical machine
IP adjust every time the pod restart,so -> service
2.2 Service &Ingress
Ingress: cause the node-ip is not very practical.
2.3 ConfigMap & Secret
change name: mogo-db-service -> mogo-db
! ConfigMap is for non-confidential data only! ->Secret
2.4 Volume
2.5 Deployment & StatefulSet
my-app died -> replicates everything!
Define blueprint for Pods: specify how many replicas you want to have
work with deployments instead of pods.
! DB can’t be replicated via Deployment!
DB has state -> data inconsistence - > StatefulSet
however, deploying StatefulSet not easy -> common practice: DB hosted outside of k8s cluster.
3. Kubernetes Configuration
talk to API server
C-M
each configuration file has 3 parts
4. Minikube & Kubeetcl - Setup k8s cluster locally
- what’s MiniKube & Kubeetcl?
- How to setup?
复查一下哪里出错了。
4.1 MiniKube & Kubeetcl
**MiniKube **
Master and Node processes run in ONE machine
Node: docker runtime pre-installed.
Kubeetcl: Command line tool for K8s cluster - interact
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
brew install hyperkit
Docker prefered!
minikube start --vm-driver docker
😑 翻墙也不行,miniKube FAQ已经为我们提供方法权限问题按提示修改即可。
minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
Or Start your cluster
minikube start --vm-driver=hyperkit
get status of nodes
kubectl get nodes
minikube status
4.2.2 Create Config Files
**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.
-
label: for pods, label is a required field. for other compoments, it is optional.
-
Selector: which Pods belong to Deployment?
-
-
Service:
---
= you can have multiple YAML configurations within a filesimple to keep port and target port the same.
How do we pass these environment variables to mongo application?
same with password
similar with webapp:
Configure external Service
4.2.3 Deploy all resources in MiniKube cluster
4.3 Interacting with K8s cluster
get all components in cluster
kubectl get all
kubectl get pod | configmap | secret
kubectl --help
kubectl get pod
kubectle logs <podName>
Acess WebApp in Browser
kubectl get svc
minikube ip
不知道怎么回事,上面的不行,下面的行
minikube service webapp-service --url
5. Main Kubectl Commands
minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
kubectl create deployment nginx-delp --image=nginx
replicaset : a layer between deployment and pod.
kubectl get replicaset
Everything below Deployment is handled by k8s.
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
kubectl describe pod [pod name]
好墨迹呀!!
Enter the container
kubectl exec -it [pod name] -- bin/bash
Delete deplyment & Apply configuration file
kubectl delete deployment [name]
Configuration files is a better way.
kubectl apply -f [file name]
Summarize
https://www.youtube.com/watch?v=UPJpmOKGKzU
看完三小时的课程后,学习openFaas,部署k3s+openfaas
更多推荐
所有评论(0)