kubernetes 基础知识

Posted by Sunday on 2018-12-09

Kubernetes架构

11

Kubernetes基本概念

Pod
 - 组功能相关的Container的封装
 - 共享存储和Network Namespace
 - K8S调度和作业运行的基本单位(Scheduler调度,Kubelet运行)
 - 容易“走失”,需要Workload和Service的“呵护”
Workloads (Deployment, StatefulSet, DaemonSet, Job…)
 - 组功能相关的Pod的封装
Service
 - Pod“防失联”
 - 给一组pod设置反向代理

Kubectl交互命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Basic Commands (Beginner):
create 从文件或stdin创建资源
expose 为deployment,pod创建Service。
run Run a particular image on the cluster
set Set specific features on objects

Basic Commands (Intermediate):
get 最基本的查询命令。如 kubectl get rs|deploy|svc
explain 查看资源定义。如 kubectl explain replicaset
edit 使用系统编辑器编辑资源。如 kubectl edit deploy/foo
delete 删除指定资源,支持文件名、资源名、label selector。 如 kubectl delete po -l foo=bar


Deploy Commands:
rollout Deployment, Daemonset的升级过程管理(查看状态、操作历史、暂停升级、恢复升级、回滚等)
rolling-update 客户端滚动升级,仅限ReplicationController
scale 修改Deployment, ReplicaSet, ReplicationController, Job的实例数
autoscale 为Deploy, RS, RC配置自动伸缩规则(依赖heapster和hpa)

Cluster Management Commands:
certificate Modify certificate resources.
cluster-info 查看集群信息
top 查看资源占用率(依赖heapster)
cordon 标记节点为unschedulable
uncordon 标记节点为schedulable
drain 驱逐节点上的应用,准备下线维护
taint 修改节点taint标记

Troubleshooting and Debugging Commands:
describe 查看资源详情
logs 查看pod内容器的日志
attach Attach到pod内的一个容器
exec 在指定容器内执行命令
port-forward 为pod创建本地端口映射
proxy 为Kubernetes API server创建代理
cp 容器内外/容器间文件拷贝

Advanced Commands:
apply 从文件或stdin创建/更新资源
patch 使用strategic merge patch语法更新对象的某些字段
replace 从文件或stdin更新资源
convert 在不同API版本之间转换对象定义

Settings Commands:
label 给资源设置label
annotate 给资源设置annotation
completion 获取shell自动补全脚本(支持bash和zsh)

Other Commands:
api-versions Print the supported API versions on the server, in the form of "group/version"
config 修改kubectl配置(kubeconfig文件),如context
help Help about any command

使用run命令生成yaml

1
kubectl run --image=nginx my-deploy -o yaml --dry-run > my-deploy.yaml

使用get命令导出yaml

1
kubectl get statefulset/foo -o=yaml --export > new.yaml

Pod亲和性帮助

1
kubectl explain pod.spec.affinity.podAffinity

kubectl get pod –watch
kubectl get deployment/nginx
kubectl get pod -o wide
kubectl describe deployment/nginx
kubectl create service clusterip my-svc-ip –tcp=80:8080
kubectl describe service my-svc-cp

Deployments

Deployment控制器为Pod和ReplicaSet提供声明性更新。