first commit
This commit is contained in:
commit
ba848e218d
1001 changed files with 152333 additions and 0 deletions
160
CloudNative/Kubernetes/Base/k8s基础.md
Normal file
160
CloudNative/Kubernetes/Base/k8s基础.md
Normal file
|
@ -0,0 +1,160 @@
|
|||
### 端口:
|
||||
master
|
||||
apiserver:6443(https), 8080
|
||||
etcd:2379(外部访问。client访问),2380(etcd集群互访)
|
||||
kubelet: 10250
|
||||
kube-scheduler(healthy):10251
|
||||
controler-manager(healthy):10252
|
||||
cloud-manager(healthy):10253
|
||||
kubulet api: 10255
|
||||
kube-proxy(healthy):10256
|
||||
|
||||
|
||||
|
||||
|
||||
### k8s架构
|
||||
master:api server,scheduler,controller manager
|
||||
node:kubelet,kube-proxy
|
||||
|
||||
### k8s最小调度单元:pod
|
||||
pod有标签(label),标签选择器(label selector)
|
||||
|
||||
pod分为自主式与控制器管理的pod
|
||||
|
||||
##控制器类型:
|
||||
RepllicationController
|
||||
ReplicaSet
|
||||
Deployment
|
||||
StatefulSet
|
||||
DaemonSet
|
||||
Job
|
||||
CronJob
|
||||
HPA(HorizontalPodAutoscaler,自动扩展)
|
||||
|
||||
##CNI:
|
||||
flannel:网络配置
|
||||
calica:网络配置,网络策略
|
||||
...
|
||||
|
||||
### 资源对象:
|
||||
负载类型资源:pod,ReplicaSet,Deployment,service,Job,CronJob
|
||||
|
||||
### pod生命周期:
|
||||
初始化容器:init container
|
||||
启动后:start post
|
||||
存活状态检测:liveness probe
|
||||
就绪检测:readiness probe
|
||||
停止前: pre stop
|
||||
---
|
||||
显示集群的运行信息:kubectl cluster-info
|
||||
|
||||
显示集群各组件的运行信息:kubectl get cs
|
||||
|
||||
显示apiserver各版本:kubectl api-version
|
||||
|
||||
查看ReplicaSet的apiVersion:kubelet explian rs
|
||||
|
||||
获取pod简单信息:kubectl get pod
|
||||
|
||||
获取pod信息并显示label:kubectl get pod --show-labels
|
||||
|
||||
获取pod详细信息:kubectl get pod -o wide
|
||||
|
||||
获取pod信息并显示为yaml格式:kubectl get pod -o yaml
|
||||
|
||||
持续查看pod信息:kubectl get pod -w (watch)
|
||||
|
||||
显示标签中含有xxx标签的pod:kubectl get pod -l xxx
|
||||
|
||||
为pod打标签:kubectl label pod pod名称 标签key=标签value --overwrite
|
||||
|
||||
查看pod的描述信息:kubectl describe xxx
|
||||
|
||||
扩缩容器数量:kubectl scale --replicas=3 xxx
|
||||
|
||||
回滚到上一个版本:kubectl rollout undo pod名称
|
||||
|
||||
修改配置信息:kubectl edit
|
||||
|
||||
查看资源字段定义及使用:kubectl explain 资源字段
|
||||
|
||||
从dockerhub中拉取最新的nginx镜像,运行端口80,一个副本:kubectl run nginx-deploy --image=nginx --port=80 --relicas=1
|
||||
|
||||
查看pod日志:kubelet logs pod名称 容器名称
|
||||
|
||||
进入pod中的容器里:kubelet exec -it pod名称 -c 容器名称 -- /bin/sh
|
||||
|
||||
删除资源:kubectl delete
|
||||
删除指定配置资源清单:kubectl delete -f xxx.yaml
|
||||
删除指定资源:kubelet delete 资源名称 -n namespace
|
||||
|
||||
禁止pod调度到该node:kubectl cordon <none>
|
||||
|
||||
驱逐节点上的所有pod:kubectl drain <node>
|
||||
|
||||
节点重新添加到集群:kubectl uncordon <node>
|
||||
|
||||
为节点设置污点:kubectl taint nodes node1 key1=value1:NoSchedule
|
||||
|
||||
---
|
||||
|
||||
大部分资源的配置清单
|
||||
---
|
||||
apiVersion:group/version # kubectl explain 资源类型
|
||||
|
||||
kind: 资源类别
|
||||
|
||||
metadata:元数据
|
||||
name:资源名称
|
||||
namespace:资源命名空间
|
||||
labels:标签
|
||||
annotations:
|
||||
spec:规格,期望的状态
|
||||
containers:
|
||||
livenessProbe:存活探针
|
||||
httpGet:
|
||||
port:端口或容器中ports定义的端口对应的name
|
||||
path:/index.html
|
||||
exec:
|
||||
command:[命令或脚本]
|
||||
initialDelaySeconds:数字,延迟时间,秒
|
||||
periodSeconds:数字,探测间隔,秒
|
||||
readinessProbe:就绪探针
|
||||
httpGet:
|
||||
port:端口或容器中ports定义的端口对应的name
|
||||
path:/index.html
|
||||
exec:
|
||||
command:[命令或脚本]
|
||||
initialDelaySeconds:数字,延迟时间,秒
|
||||
periodSeconds:数字,探测间隔,秒
|
||||
- name:名称
|
||||
image:镜像地址
|
||||
args:[entrypoint]
|
||||
lifecycle:存活钩子
|
||||
postStart:
|
||||
exec:
|
||||
command
|
||||
- name:名称
|
||||
image:镜像地址
|
||||
imagePullPolicy:Always[总是去拉取镜像],Never[从来不去拉取],IfNotPresent[本地不存在,拉取]
|
||||
ports:端口列表
|
||||
- name:端口名称
|
||||
containerPort:端口
|
||||
- name:端口名称
|
||||
containerPort:端口
|
||||
protocol:协议,默认tcp
|
||||
command:[命令]
|
||||
|
||||
restartPolicy:Always[总是重启],OnFailure[失败重启],Never[不重启],默认时Always
|
||||
|
||||
nodeSelector:{节点标签选择器}
|
||||
nodeName:节点名称
|
||||
annotations:与label不同地方在于,它不能用于挑选资源对象,仅用于为对象提供“元数据”
|
||||
|
||||
|
||||
status:状态只读字段,不需要定义
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue