KUBECTL management tools deployed on node nodes
# 设置集群项中名为kubernetes的apiserver地址与根证书kubectl config set-cluster kubernetes --server=https://192.168.1.107:6443 --certificate-authority=ca.pem# 设置用户项中cluster-admin用户证书认证字段kubectl config set-credentials cluster-admin --certificate-authority=ca.pem --client-key=admin-key.pem --client-certificate=admin.pem# 设置环境项中名为default的默认集群和用户kubectl config set-context default --cluster=kubernetes --user=cluster-admin# 设置默认环境项为defaultkubectl config use-context default
Command
create通过文件名或标准输入创建资源expose将一个资源公开为一个新的Servicerun在集群中运行一个特定的镜像set在对象上设置特定的功能get显示一个或多个资源 explain文档参考资料。edit使用默认的编辑器编辑一个资源。delete通过文件名、 标准输入、 资源名称或标签选择器来删除资源。rollout管理资源的发布rolling-update对给定的复制控制器滚动更新scale扩容或缩容Pod数量, Deployment、 ReplicaSet、 RC或Jobautoscale创建一个自动选择扩容或缩容并设置Pod数量certificate×××资源cluster-info显示集群信息top显示资源(CPU/Memory/Storage) 使用。 需要Heapster运行cordon标记节点不可调度uncordon标记节点可调度drain维护期间排除节点taint
Command
describe显示特定资源或资源组的详细信息logs在一个Pod中打印一个容器日志。 如果Pod只有一个容器, 容器名称是可选的attach附加到一个运行的容器exec执行命令到容器port-forward转发一个或多个本地端口到一个podproxy运行一个proxy到Kubernetes API servercp拷贝文件或目录到容器中auth检查授权apply通过文件名或标准输入对资源应用配置patch使用补丁修改、 更新资源的字段replace通过文件名或标准输入替换一个资源convert不同的API版本之间转换配置文件label更新资源上的标签annotate更新资源上的注释completion用于实现kubectl工具自动补全api-versions打印受支持的API版本config修改kubeconfig文件(用于访问API, 比如配置认证信息)help所有命令帮助plugin运行一个命令行插件version打印客户端和服务版本信息
1, create
Kubectl run Nginx--replicas=3--labels= "app=example"--image=nginx:1.10--port=80
2, view
Kubectl get Deploy
Kubectl get pods--show-labels
Kubectl get pods-l app=example
Kubectl get pods-o wide
3, release
Kubect L Expose deployment Nginx--port=88--type=nodeport--target-port=80--name=nginx-service
Kubectl describe service Nginx-service
4, troubleshooting
Kubectl describe TYPE name_prefix
Kubectl logs nginx-xxx
Kubectl exec–it nginx-xxx Bash
5, update
Kubectl set image Deployment/nginx nginx=nginx:1.13
or
Kubectl edit Deployment/nginx
Resource Release Management:
Kubectl rollout status Deployment/nginx
Kubectl rollout history Deployment/nginx
Kubectl Rollout History Deployment/nginx--revision=3
Kubectl Scale deployment Nginx--replicas=10
6, rollback
Kubectl rollout undo Deployment/nginx-deployment
Kubectl rollout undo Deployment/nginx-deployment--to-revision=3
7, delete
Kubectl Delete Deploy/nginx
Kubectl Delete svc/nginx-service
YAML Configuration file Management Resources
Configuration file Description:
- When defining the configuration, specify the latest stable version API (currently v1);
- The configuration file should be stored in a version control repository outside the cluster. Quick rollback of configuration, re-creation and recovery, if required;
- The configuration file should be written in YAML format, not JSON. Although these formats are available, YAML is more user-friendly;
- You can combine related objects into a single file, which is usually easier to manage;
- Do not unnecessarily specify default values, simple and minimal configuration to reduce errors;
- Describe an object description in a note for better maintenance.
vim nginx-deployment.ymlapiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.13 ports: - containerPort: 80---apiVersion: v1kind: Servicemetadata: name: nginx-servicespec: selector: app: nginx ports: - name: http port: 80 protocol: TCP targetPort: 80 type: NodePortkubectl create -f nginx-deployment.yml
kubernets1.10.1--Basic operation (i)