乐趣区

关于k8s: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 裸露进来  clusteip  ingress
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 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: template  spec : 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
退出移动版