二、Kubernetes快速入门
(1)Kubernetes集群的部署方法及部署要点
(2)部署Kubernetes分布式集群
(3)kubectl使用基础
1、简介
kubectl就是API service的客户端程序,通过连接master节点上的API service实现k8s对象、资源的增删改查操作。
对象:node、pod、service、controller(replicaset,deployment,statefulet,daemonset,job,cronjob)
2、子命令
分类
#基本命令
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 #自动改变
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 #描述资源的详细信息
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(高级命令):
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
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:
alpha :Commands for features in alpha
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]
3、创建Pod
创建一个控制器名为nginx-deploy,镜像版本为nginx:1.14-alpine的Pod,暴露端口80,副本为1
[root@master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1
如下图,此时可以看出创建成功了,而且在node02节点上,网段是10.244.2.0/24,而node01节点的网段是10.244.1.0/24。
可通过node01节点进行访问试试,而10.244.2.2是pod地址,只能在k8s集群中内部才能访问。
Pod的客户端有两类:其他Pod和集群外的客户端
(4)命令式应用部署、扩缩容、服务暴露