kubernetes 的管理之:Node 的管理

慣例,先介紹一下關鍵組件

一、Master

集羣控制節點,在每個Kubernetes集羣裏都需要有一個Master來負責整個集羣的管理和控制工作,基本上Kubernetes的所有命令都發個它,它負責具體的執行過程。是整個集羣的大腦。

Master上關鍵進程:

  • Kubernetes API Server(kube-apiserver):提供了HTTP Rest 接口的關鍵服務進程,是kubernetes裏所有資源的增,刪,改,查的操作的唯一入口,也是集羣控制的入口進程。
  • Kubernetes Controller Manager(kube-controller-manager):kubernetes 裏所有資源對象的自動化控制中心,可以將其理解爲資源對象的“大總管”。
  • Kubernetes Scheduler(kube-scheduler):負責資源(Pod)的調度。
  • Etcd服務:kubernetes上資源對象的數據被保存在其中。

二、Node

Kubernetes工作負載節點,除了master ,Kubernetes集羣中其他的機器被稱爲Node,Node可以是物理機,也可以是虛擬機,Node 也可以被看錯kubernetes上的資源,進行調度和配置。

Node上關鍵進程

  • kubelet:負責Pod對應容器的創建、起停的任務,與master協作,管理集羣。
  • kube-proxy:實現Kubnernetes Service 的通信與負載均衡機制的主要組件。
  • Docker-Engine:Docker 引擎,負責本機的容器創建管理工作。

三、client-go Node 管理

1. Node 的隔離和恢復

其實Node 的隔離和恢復,主要是通過spec.unscheduled 字段進行控制

k8s.io/api/core/v1/types.go

// NodeSpec describes the attributes that a node is created with.
type NodeSpec struct {
	// PodCIDR represents the pod IP range assigned to the node.
	// +optional
	PodCIDR string `json:"podCIDR,omitempty" protobuf:"bytes,1,opt,name=podCIDR"`
	// ID of the node assigned by the cloud provider in the format: <ProviderName>://<ProviderSpecificNodeID>
	// +optional
	ProviderID string `json:"providerID,omitempty" protobuf:"bytes,3,opt,name=providerID"`
	// Unschedulable controls node schedulability of new pods. By default, node is schedulable.
	// More info: https://kubernetes.io/docs/concepts/nodes/node/#manual-node-administration
	// +optional
	Unschedulable bool `json:"unschedulable,omitempty" protobuf:"varint,4,opt,name=unschedulable"`
	// If specified, the node's taints.
	// +optional
	Taints []Taint `json:"taints,omitempty" protobuf:"bytes,5,opt,name=taints"`
	// If specified, the source to get node configuration from
	// The DynamicKubeletConfig feature gate must be enabled for the Kubelet to use this field
	// +optional
	ConfigSource *NodeConfigSource `json:"configSource,omitempty" protobuf:"bytes,6,opt,name=configSource"`

	// Deprecated. Not all kubelets will set this field. Remove field after 1.13.
	// see: https://issues.k8s.io/61966
	// +optional
	DoNotUse_ExternalID string `json:"externalID,omitempty" protobuf:"bytes,2,opt,name=externalID"`
}

當上述Node結構中Unschedulable 字段設置爲true,後續被創建的Node就不會被調度到該Node上了。
注:其上運行的Pod不會自動停止,需要人工干預,此行爲跟Node“失聯”不同。

client-go/kubernetes/type/core/v1/node.go

// NodeInterface has methods to work with Node resources.
type NodeInterface interface {
	Create(*v1.Node) (*v1.Node, error)
	Update(*v1.Node) (*v1.Node, error)
	UpdateStatus(*v1.Node) (*v1.Node, error)
	Delete(name string, options *metav1.DeleteOptions) error
	DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error
	Get(name string, options metav1.GetOptions) (*v1.Node, error)
	List(opts metav1.ListOptions) (*v1.NodeList, error)
	Watch(opts metav1.ListOptions) (watch.Interface, error)
	Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Node, err error)
	NodeExpansion
}

可以通過上述接口,實現對Node的相關管理。

2、Node 的擴容

在實際生產關係中,會出現服務器資源不足的情況,這樣就需要對集羣進行擴容,增加Node,那麼如何擴容呢?
非常簡單,在新的node上安裝以上Docker,kubelet,kube-proxy三個服務,並將啓動參數master配置爲需要加入的集羣Master地址即可。kubelet會自動註冊,這樣就完成了擴容,沒有複雜的配置,無需起停集羣。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章