k8s是一个基于容器的自动化的容器编排平台,负责应用的部署、弹性、管理
API Server
处理api操作,k8s中所有的组件都会和API Server进行连接,组件和组件之间,一般不进行独立的连接,都依赖于API Server进行消息的传递
Controller
控制器,用来完成对集群状态的一些管理
Scheduler
调度器,完成调度的操作
Etcd
分布式存储系统,API Server中这些所需要的原信息都被放置在etcd中,其本身是一个高可用系统,通过etcd保证整个k8s的master组件的高可用性
真正运行业务负载的地方,每个业务负载会以Pod的形式运行;一个Pod中运行的一个或多个容器,真正去运行这些Pod的组件的为kubelet,kubelet也为Node上最为关键的组件,通过API Server接收到所需要Pod运行的状态,然后提交到Container Runtime组件中
在OS上创建容器所需要的运行环境,把容器或者Pod运行起来,k8s不会直接运行网络存储的操作,会靠Storage Plugin或者Network Plugin来进行操作
在k8s自己的环境中,也会有Network,提供Service network来进行搭网、组网,其组件为Kube-proxy,利用iptable的能力来进行组建k8s的Network,即为cluster network
用户可以通过UI或者CLI提交一个Pod给k8s进行部署,这个Pod请求首先会通过CLI或者UI提交给k8s API Server,下一步API Server会把这个信息写入到他的存储系统etcd,之后Scheduler会通过API Server的watch或者叫做notification机制得到这个信息: 有一个Pod需要被调度
此时Scheduler会根据他的内存状态进行一次调度决策,在完成这次调度之后,回向API Server report说:“OK! 这个Pod需要被调度到某一个节点上”
此时API Server接收到这次操作之后,会把这次的结果再次写到etcd中,然后API Server会通知相应的节点进行这次Pod真正的执行启动,相应节点的kubelet会得到这个通知,kubelet就回去调Container runtime来真正去启动配置这个容器和这个容器的运行环境,去调度Storage Plugin来配置存储,Network Plugin去配置网络
卷/抽象的概念,用来管理k8s存储,用来声明在Pod中的容器可以访问文件目录,一个卷可以被挂载在Pod中一个或者多个容器的指定路径下面,一个Volume可以支持多种的后端存储,eg:本地存储、ceph、GlusterFS
]# cat > nginx.yaml <<-EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF
]# kubectl apply -f nginx.yaml
查看deployment变更情况
kubectl get --watch deployment
查看deployment的详细信息
]# kubectl describe deployment nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Tue, 12 Jan 2021 12:08:52 +0800
Labels:
Annotations: deployment.kubernetes.io/revision: 1
kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"cj-ops"},"spec":{"replicas...
Selector: app=nginx
Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx:1.7.9
Port: 80/TCP
Host Port: 0/TCP
Environment:
Mounts:
Volumes:
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets:
NewReplicaSet: nginx-deployment-6dd86d77d (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 45m deployment-controller Scaled up replica set nginx-deployment-6dd86d77d to 2
]# cat > nginx_update.yaml <<-EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.8 # update nginx version
ports:
- containerPort: 80
EOF
]# kubectl apply -f nginx_update.yaml
查看deployment的详细信息
]# kubectl describe deployment nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Tue, 12 Jan 2021 12:08:52 +0800
Labels:
Annotations: deployment.kubernetes.io/revision: 2
kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"cj-ops"},"spec":{"replicas...
Selector: app=nginx
Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx:1.8 # succes update nginx version
Port: 80/TCP
Host Port: 0/TCP
Environment:
Mounts:
Volumes:
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets:
NewReplicaSet: nginx-deployment-7c96f597c8 (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 50m deployment-controller Scaled up replica set nginx-deployment-6dd86d77d to 2
Normal ScalingReplicaSet 2m38s deployment-controller Scaled up replica set nginx-deployment-7c96f597c8 to 1
Normal ScalingReplicaSet 2m24s deployment-controller Scaled down replica set nginx-deployment-6dd86d77d to 1
Normal ScalingReplicaSet 2m24s deployment-controller Scaled up replica set nginx-deployment-7c96f597c8 to 2
Normal ScalingReplicaSet 2m9s deployment-controller Scaled down replica set nginx-deployment-6dd86d77d to 0
]# cat > nginx_scale.yaml <<-EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
selector:
matchLabels:
app: nginx
replicas: 4 # scale 2 to 4
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.8
ports:
- containerPort: 80
EOF
]# kubectl apply -f nginx_update.yaml
查看deployment的详细信息
]# kubectl describe deployment nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Tue, 12 Jan 2021 12:08:52 +0800
Labels:
Annotations: deployment.kubernetes.io/revision: 2
kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"cj-ops"},"spec":{"replicas...
Selector: app=nginx
Replicas: 4 desired | 4 updated | 4 total | 4 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx:1.8
Port: 80/TCP
Host Port: 0/TCP
Environment:
Mounts:
Volumes:
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets:
NewReplicaSet: nginx-deployment-7c96f597c8 (4/4 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 41m deployment-controller Scaled up replica set nginx-deployment-7c96f597c8 to 1
Normal ScalingReplicaSet 41m deployment-controller Scaled down replica set nginx-deployment-6dd86d77d to 1
Normal ScalingReplicaSet 41m deployment-controller Scaled up replica set nginx-deployment-7c96f597c8 to 2
Normal ScalingReplicaSet 40m deployment-controller Scaled down replica set nginx-deployment-6dd86d77d to 0
Normal ScalingReplicaSet 2m59s deployment-controller Scaled up replica set nginx-deployment-7c96f597c8 to 4
… …