本随笔接前两两章,建立离master主节点和node01、node02、node03三个节点
kubectl子命令
master ~]# kubectl
kubectl controls the Kubernetes cluster manager. Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/ Basic Commands (Beginner): create Create a resource from a file or from stdin. //增 expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service run Run a particular image on the cluster set Set specific features on objects Basic Commands (Intermediate): explain Documentation of resources get Display one or many resources //查 edit Edit a resource on the server //改 delete Delete resources by filenames, stdin, resources and names, or by resources and label selector //删除 Deploy Commands: rollout Manage the rollout of a resource //滚动 scale Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job //手动改变应用程序的规模 autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController //自动改变,即创建HPA Cluster Management Commands: //集群管理 certificate Modify certificate resources. cluster-info Display cluster info //集群信息 top Display Resource (CPU/Memory/Storage) usage. cordon Mark node as unschedulable //标记一个节点不可被调用 uncordon Mark node as schedulable //标记节点可被调用 drain Drain node in preparation for maintenance taint Update the taints on one or more nodes //给节点增加污点,作用是控制是否被调用 Troubleshooting and Debugging Commands: describe Show details of a specific resource or group of resources //描述资源的详细信息,例如 master ~]# kubectl describe node node01 logs Print the logs for a container in a pod attach Attach to a running container exec Execute a command in a container port-forward Forward one or more local ports to a pod proxy Run a proxy to the Kubernetes API server cp Copy files and directories to and from containers. auth Inspect authorization Advanced Commands: diff Diff live version against would-be applied version apply Apply a configuration to a resource by filename or stdin patch Update field(s) of a resource using strategic merge patch replace Replace a resource by filename or stdin wait Experimental: Wait for a specific condition on one or many resources. convert Convert config files between different API versions kustomize Build a kustomization target from a directory or a remote url. Settings Commands: label Update the labels on a resource annotate Update the annotations on a resource completion Output shell completion code for the specified shell (bash or zsh) Other Commands: api-resources Print the supported API resources on the server api-versions Print the supported API versions on the server, in the form of "group/version" config Modify kubeconfig files plugin Provides utilities for interacting with plugins. version Print the client and server version information Usage: kubectl [flags] [options] Use "kubectl <command> --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands).
描述一个资源的详细信息
[root@master ~]# kubectl describe node master Name: master Roles: master Labels: beta.kubernetes.io/arch=amd64 beta.kubernetes.io/os=linux kubernetes.io/arch=amd64 kubernetes.io/hostname=master kubernetes.io/os=linux node-role.kubernetes.io/master= Annotations: flannel.alpha.coreos.com/backend-data: {"VtepMAC":"2e:6c:70:78:ed:70"} flannel.alpha.coreos.com/backend-type: vxlan flannel.alpha.coreos.com/kube-subnet-manager: true flannel.alpha.coreos.com/public-ip: 192.168.184.141 kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock node.alpha.kubernetes.io/ttl: 0 volumes.kubernetes.io/controller-managed-attach-detach: true CreationTimestamp: Fri, 31 May 2019 20:34:59 +0800 Taints: node-role.kubernetes.io/master:NoSchedule //表示只要不是master的组件都不能调度到master上 Unschedulable: false Conditions: Type Status LastHeartbeatTime LastTransitionTime Reason Message ---- ------ ----------------- ------------------ ------ ------- MemoryPressure False Mon, 03 Jun 2019 22:20:17 +0800 Fri, 31 May 2019 20:34:53 +0800 KubeletHasSufficientMemory kubelet has sufficient memory available DiskPressure False Mon, 03 Jun 2019 22:20:17 +0800 Fri, 31 May 2019 20:34:53 +0800 KubeletHasNoDiskPressure kubelet has no disk pressure PIDPressure False Mon, 03 Jun 2019 22:20:17 +0800 Fri, 31 May 2019 20:34:53 +0800 KubeletHasSufficientPID kubelet has sufficient PID available Ready True Mon, 03 Jun 2019 22:20:17 +0800 Mon, 03 Jun 2019 22:06:07 +0800 KubeletReady kubelet is posting ready status Addresses: InternalIP: 192.168.184.141 Hostname: master Capacity: cpu: 4 ephemeral-storage: 12786Mi hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 1867048Ki pods: 110 Allocatable: cpu: 4 ephemeral-storage: 12066383443 hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 1764648Ki pods: 110 System Info: Machine ID: 45c658713b3b423387314d097b36aa61 System UUID: 7C8C4D56-7732-E896-C85E-040A2FCEF804 Boot ID: 474da659-6243-4a63-a5f9-2e436260b3d2 Kernel Version: 3.10.0-693.el7.x86_64 OS Image: CentOS Linux 7 (Core) Operating System: linux Architecture: amd64 Container Runtime Version: docker://18.9.6 Kubelet Version: v1.14.2 Kube-Proxy Version: v1.14.2 PodCIDR: 10.244.0.0/24 Non-terminated Pods: (8 in total) Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE --------- ---- ------------ ---------- --------------- ------------- --- kube-system coredns-fb8b8dccf-42b7j 100m (2%) 0 (0%) 70Mi (4%) 170Mi (9%) 3d1h kube-system coredns-fb8b8dccf-bjv95 100m (2%) 0 (0%) 70Mi (4%) 170Mi (9%) 3d1h kube-system etcd-master 0 (0%) 0 (0%) 0 (0%) 0 (0%) 3d1h kube-system kube-apiserver-master 250m (6%) 0 (0%) 0 (0%) 0 (0%) 3d1h kube-system kube-controller-manager-master 200m (5%) 0 (0%) 0 (0%) 0 (0%) 3d1h kube-system kube-flannel-ds-amd64-w4jfh 100m (2%) 100m (2%) 50Mi (2%) 50Mi (2%) 2d18h kube-system kube-proxy-f88gd 0 (0%) 0 (0%) 0 (0%) 0 (0%) 3d1h kube-system kube-scheduler-master 100m (2%) 0 (0%) 0 (0%) 0 (0%) 3d1h Allocated resources: (Total limits may be over 100 percent, i.e., overcommitted.) Resource Requests Limits -------- -------- ------ cpu 850m (21%) 100m (2%) memory 190Mi (11%) 390Mi (22%) ephemeral-storage 0 (0%) 0 (0%) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Starting 14m kubelet, master Starting kubelet. Normal NodeHasSufficientMemory 14m kubelet, master Node master status is now: NodeHasSufficientMemory Normal NodeHasNoDiskPressure 14m kubelet, master Node master status is now: NodeHasNoDiskPressure Normal NodeHasSufficientPID 14m kubelet, master Node master status is now: NodeHasSufficientPID Normal NodeNotReady 14m kubelet, master Node master status is now: NodeNotReady Normal NodeAllocatableEnforced 14m kubelet, master Updated Node Allocatable limit across pods Normal NodeReady 14m kubelet, master Node master status is now: NodeReady
[root@master ~]# kubectl version //查看客户端和服务器端的版本 Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean",
BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean",
BuildDate:"2019-05-16T16:14:56Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
[root@master ~]# kubectl cluster-info //查看集群信息 Kubernetes master is running at https://192.168.184.141:6443 //向外输出的API Server地址 KubeDNS is running at https://192.168.184.141:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
//相当于CoreDNS,运行获取路径时,从集群外部访问的执行端口转发的代理的访问方式 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
三个重要的附件:kube-proxy、CoreDNS、flannel