kubectl常用命令

查看主节点

kubectl get node

集群信息
kubectl cluster-info

pod信息
kubectl get pods -A

deployment
kubectl get deployment -A

基本概念:
container pods:最小管理单位有多个容器共享网络127.0.0.1之间可以共同访问共享进程共享主机名 service :暴露服务负载均衡k8s外部nodeport 暴露出去clusteipingress deployment :控制器保证pods固定数量每个节点上运行(proxy flannel daemonset )k8s coredns:服务注册与发现

创建deployment:
kubectl create deployment mynginx --image=nginx:1.8 --replicas=3 kubectl create deployment mynginx --image=docker.io/library/nginx

查看deployment
kubectl get deployment -o wide ------>包含selector deployment通过selector来找到对应的pod类似普罗米修斯的label

删除deployment
kubectl delete deployment mynginx

修改pod副本数量
kubectl scale deployment mynginx --replicas=3

【kubectl常用命令】查看详情信息
kubectl describe deployment/pod mynginx

暴露服务
kubectl expose deployment mynginx --type=NodePort --port=8888 --targetPort=80

查看服务:kubectl get service
kubectl run -it busybox --image=busybox -- /bin/sh

查看资源版本信息:
kubectl api-resources

查看所有api版本
kubectl api-versions

编辑deployment
kubectl edit deploy mynginx apiversion metadata :label spec: templatespec : container: status: 当前deployment数量

查看cpu内存等信息
kubectl top pod mynginx

查看日志信息
kubectl logs mynginx-77f6b78767-7r6sz

进入执行命令
kubectl exec -it myngix /bin/bash

拷贝
kubectl cp index.html mynginx-77f6b78767-7r6sz:/usr/share/nginx/html

yml文件
kubectl explain apply

yml文件:
--- apli-version: apps/v1 kind: Deployment metadata: name: web namespace: default labels: env: test spec: replicas: 3 selector: matchLabels: app: web env: test template: metadata: labels: app: web env: test spec: container: - name: nginx-web image: nginx ports: - name: http containerPort: 80 protocal: TCP - name: redis image: redis ports: - name: redis containerPort: 6379 protocol: TCP --- apiVersion: v1 kind: service metadata: name: cmdb-service labels: env: test spec: type: NodePort selector: env: test app: cmdb ports: - name: http port: 80 protocol: TCP -name: redis port: 8888 targetPort: 6379

    推荐阅读