Kubernetes 完成一个神奇的功能
自动分配资源,节约人力
-
负载均衡
-
运行环境放到一个Node里面,需要就通过Node的load balance分配资源
-
Requests 和 limits 来平衡
-
更新代码的时候不需要停下生产环境
-
拉取新的镜像称新的pod
-
新代码的pod和久的pod共存
资源不够的时候,申请更多资源
- 直接更换Node
docker以上运行
- 配置好container好之后,每次新的pod都来拉去环境
Kubernetes 如何部署
-
申请好Cluster
-
配置好NODE
-
配置好路由网关
-
配置好配置好container
-
配置好git代码
-
就配置完了
kubernetes 结构
Cluster
image-20190328105153609.pngMaster
The Master is responsible for managing the cluster. The master coordinates all activities in your cluster, such as scheduling applications, maintaining applications' desired state, scaling applications, and rolling out new updates.
Kubelet
Each node has a Kubelet, which is an agent for managing the node and communicating with the Kubernetes master. The node should also have tools for handling container operations, such as Docker or rkt. A Kubernetes cluster that handles production traffic should have a minimum of three nodes.
Node
image-20190328110105564.pngContainer
image-20190328110514860.pngPODs
Kubernetes created a Pod to host your application instance. A Pod is a Kubernetes abstraction that represents a group of one or more application containers (such as Docker or rkt), and some shared resources for those containers. Those resources include:
-
Shared storage, as Volumes
-
Networking, as a unique cluster IP address
-
Information about how to run each container, such as the container image version or specific ports to use
Services
A Service in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them. Services enable a loose coupling between dependent Pods. A Service is defined using YAML (preferred) or JSON, like all Kubernetes objects. The set of Pods targeted by a Service is usually determined by a LabelSelector (see below for why you might want a Service without including selector
in the spec).
Although each Pod has a unique IP address, those IPs are not exposed outside the cluster without a Service. Services allow your applications to receive traffic. Services can be exposed in different ways by specifying a type
in the ServiceSpec:
-
ClusterIP (default) - Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster.
-
NodePort - Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service accessible from outside the cluster using
<NodeIP>:<NodePort>
. Superset of ClusterIP. -
LoadBalancer - Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Service. Superset of NodePort.
-
ExternalName - Exposes the Service using an arbitrary name (specified by
externalName
in the spec) by returning a CNAME record with the name. No proxy is used. This type requires v1.7 or higher ofkube-dns
.
Kubernetes 带来的好处
before:
物理机上运行
git代码管咯
手动分配资源
资源不够的时候需要等待
更新代码时需要停下生产环境
添加新的物理机之后需要重新配置资源
测试需要重新配置环境,需要手动分配资源
after:
docker以上运行
git tag管理代码
自动分配资源,节约人力
资源不够的时候,申请更多资源
更新代码的时候不需要停下生产环境
环境在docker里面,不会出现环境被破坏,或者重新配置环境的问题
配置好测试环境k8s,持续集成,在测试成功后,环境很容易迁移。
网友评论