kubernets1.10.1--Basic Operation (1)

The Kubectl management tool is deployed on the node node

# 设置集群项中名为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
# 设置默认环境项为default
kubectl config use-context default

Order

create
通过文件名或标准输入创建资源
expose
将一个资源公开为一个新的Service
run
在集群中运行一个特定的镜像
set
在对象上设置特定的功能
get
显示一个或多个资源    
explain
文档参考资料。
edit
使用默认的编辑器编辑一个资源。
delete
通过文件名、 标准输入、 资源名称或标签选择器来删除资源。
rollout
管理资源的发布
rolling-update
对给定的复制控制器滚动更新
scale
扩容或缩容Pod数量, Deployment、 ReplicaSet、 RC或Job
autoscale
创建一个自动选择扩容或缩容并设置Pod数量
certificate
×××资源
cluster-info
显示集群信息
top
显示资源(CPU/Memory/Storage) 使用。 需要Heapster运行
cordon
标记节点不可调度
uncordon
标记节点可调度
drain
维护期间排除节点
taint

Order

describe
显示特定资源或资源组的详细信息
logs
在一个Pod中打印一个容器日志。 如果Pod只有一个容器, 容器名称是
可选的
attach
附加到一个运行的容器
exec
执行命令到容器
port-forward
转发一个或多个本地端口到一个pod
proxy
运行一个proxy到Kubernetes API server
cp
拷贝文件或目录到容器中
auth
检查授权
apply
通过文件名或标准输入对资源应用配置
patch
使用补丁修改、 更新资源的字段
replace
通过文件名或标准输入替换一个资源
convert
不同的API版本之间转换配置文件
label
更新资源上的标签
annotate
更新资源上的注释
completion
用于实现kubectl工具自动补全
api-versions
打印受支持的API版本
config
修改kubeconfig文件(用于访问API, 比如配置认证信息)
help
所有命令帮助
plugin
运行一个命令行插件
version
打印客户端和服务版本信息

1、创建
kubectl run nginx --replicas=3 --labels="app=example" --image=nginx:1.10 --port=80
2、查看
kubectl get deploy
kubectl get pods --show-labels
kubectl get pods -l app=example
kubectl get pods -o wide
3、发布
kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service
kubectl describe service nginx-service
4、故障排查
kubectl describe TYPE NAME_PREFIX
kubectl logs nginx-xxx
kubectl exec –it nginx-xxx bash
5、 更新
kubectl set image deployment/nginx nginx=nginx:1.13
or
kubectl edit deployment/nginx
资源发布管理:
kubectl rollout status deployment/nginx
kubectl rollout history deployment/nginx
kubectl rollout history deployment/nginx --revision=3
kubectl scale deployment nginx --replicas=10
6、 回滚
kubectl rollout undo deployment/nginx-deployment
kubectl rollout undo deployment/nginx-deployment --to-revision=3
7、删除
kubectl delete deploy/nginx
kubectl delete svc/nginx-service


YAML configuration file management resource
configuration file description:

  • When defining the configuration, specify the latest stable API (currently v1);
  • Configuration files should be stored in a version control repository outside of the cluster. Quickly rollback configurations, recreate and restore if needed;
  • Configuration files should be written in YAML format, not JSON. While either of these formats can be used, YAML is more user friendly;
  • Related objects can be combined into a single file, which is often easier to manage;
  • Do not specify default values ​​unnecessarily, simple and minimal configuration reduces errors;
  • It is easier to maintain an object description in a comment.
vim nginx-deployment.yml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.13
        ports:
        - containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  type: NodePort

kubectl   create -f nginx-deployment.yml

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325519669&siteId=291194637