Open eziceice opened 4 years ago
# RUN Shell In POD
kubectl exec POD [-c CONTAINER][-i][-t][flags][-- COMMAND [args...]]
# Expose a service
kubectl expose
# Foward a local port traffic to pod
kubectl port-foward POD [LOCAL_PORT]:[POD_PORT]
# Output format
kubectl -o yaml/json
# More output
kubectl -o wide
# Logs
kubectl logs <pod-name>
kubectl logs -f <pod-name> -c <container-name>
# Edit resource in cmd
kubectl edit deploy <deployment-name>
# Copy file to host
kubectl cp <pod-name>:<pod-directory>:/tmp
# Show all available resources
kubectl api-resources
usr/local/bin
下,可以使用自定义的kubectl命令。文件名必须与以“kubectl-”开头。mountPath -> 存储卷在容器内Mount的绝对路径,少于512个字符
ports -> 容器需要暴露的端口号列表,指的是对外的端口
containerPort -> 容器需要监听的端口号,指的是容器内服务运行的端口
metadata.name
metadata.namespace
status.podIP
requests.cpu
Status | Description |
---|---|
Pending | API Server已经创建了该Pod,但在Pod内还有一个或者多个容器的镜像没有创建 |
Running | Pod内的所有容器都已经创建,且至少有一个容器处于运行状态,正在启动或者重启状态 |
Succeeded | Pod内所有容器都成功执行后退出,并且不会再重启 |
Failed | Pod内所有容器均已退出,但至少有一个容器退出为失败状态 |
Unknown | 无法获取Pod的状态 |
kubectl set image
kubectl edit deployment的配置
kubectl rollout
kubectl rollout pause deployment
kubectl rollout resume deployment
kubectl rollback
来实现回滚,必须再次提交旧版本。hostNetwork=true
,该Pod中所有容器的端口号都将被直接映射到物理机上。默认hostPort等于containerPort,如果指定了hostPort,则hostPort必须等于containerPort的值。API Server架构
Kubernetes的List-Watch用于实现数据同步代码的逻辑。客户端首先调用API Server的List接口获取相关资源对象的全量数据并将其缓存到内存中,然后启动对应资源对象的Watch协程,在接收到Watch事件后,再根据时间的类型,对内存中的全量资源列表作出相应的同步修改,从实现上来看,这是一种全量结合增量的,高性能的,近乎实时的数据同步方式。
API Server对每种资源对象都引入了一个相应不变的internal版本,每个版本只要支持转换为internal版本,就能够与其他版本进行间接转换。
Userspace: 该模式下kube-proxy会为每一个Service创建一个监听端口。发向Cluster IP的请求被Iptables规则重定向到Kube-proxy监听的端口上,Kube-proxy根据LB算法选择一个提供服务的Pod并和其建立链接,以将请求转发到Pod上。 该模式下,Kube-proxy充当了一个四层Load balancer的角色。由于kube-proxy运行在userspace中,在进行转发处理时会增加两次内核和用户空间之间的数据拷贝,效率较另外两种模式低一些;好处是当后端的Pod不可用时,kube-proxy可以重试其他Pod。
Iptables: 为了避免增加内核和用户空间的数据拷贝操作,提高转发效率,Kube-proxy提供了iptables模式。在该模式下,Kube-proxy为service后端的每个Pod创建对应的iptables规则,直接将发向Cluster IP的请求重定向到一个Pod IP。 该模式下Kube-proxy不承担四层代理的角色,只负责创建iptables规则。该模式的优点是较userspace模式效率更高,但不能提供灵活的LB策略,当后端Pod不可用时也无法进行重试。
IPVS: 该模式和iptables类似,kube-proxy监控Pod的变化并创建相应的ipvs rules。ipvs也是在kernel模式下通过netfilter实现的,但采用了hash table来存储规则,因此在规则较多的情况下,Ipvs相对iptables转发效率更高。除此以外,ipvs支持更多的LB算法。如果要设置kube-proxy为ipvs模式,必须在操作系统中安装IPVS内核模块。
1. Introduction
1.1 基本概念
kubectl
来执行增/删/查/改等操作并且把资源的状态保存在etcd中。1.1.1 Master
1.1.2 Node
1.1.3 Pod
1.1.4 Label
1.1.5 ReplicationController
1.1.6 Deployment
1.1.7 Horizontal Pod Autoscaler
1.1.8 StatefulSet
1.1.9 Service
1.1.10 Job
1.1.11 Volume
1.1.12 Persistent Volume
1.1.13 Namespace
1.1.14 Annotation
1.1.15 ConfigMap