k8s集群命令用法
一、k8s集群管理方法
二、k8s集群命令用法
查看命名空间 ~]# kubectl get namespace ~]# kubectl get ns 查看默认命名空间下所有资源 ~]# kubectl get all [-n default] 创建命名空间 ~]# kubectl create ns app ~]# kubectl delete namespace app 创建deployment类型的pod控制器 ~]# kubectl create deployment nginx-dp --image=harbor.od.com/public/nginx:v1.7.9 -n kube-public 查看deployment类型的pod控制器 ~]# kubectl get deploy -n kube-public ~]# kubectl get deployment -o wide -n kube-public 查看nginx-dp控制器的详细信息 ~]# kubectl describe deployment nginx-dp -n kube-public 查看kube-public名称空间下的pod ~]# kubectl get pods -n kube-public 进入pod nginx-dp-5dfc689474-x5nhb资源 ~]# kubectl exec -ti nginx-dp-5dfc689474-x5nhb /bin/bash -n kube-public ~]# kubectl delete pod nginx-dp-5dfc689474-gtfvv -n kube-public [--force --grace-period=0] ~]# kubectl delete deploy nginx-dp -n kube-public 暴露nginx-dp控制器80端口的service资源 ~]# kubectl expose deployment nginx-dp --port=80 -n kube-public 复制nginx-dp控制器一份 ~]# kubectl scale deployment nginx-dp --replicas=2 -n kube-public ~]# kubectl describe svc nginx-dp -n kube-public http://docs.kubernetes.org.cn/683.html 将nginx-dp-5dfc689474-f2bvt pod以yaml格式在控制台输出 ~]# kubectl get pods nginx-dp-5dfc689474-f2bvt -o yaml -n kube-public 查看service.metadata字段的帮助文档 ~]# kubectl explain service.metadata vi nginx-ds-svc.yaml apiVersion: v1 kind: Service metadata: labels: app: nginx-ds name: nginx-ds namespace: default spec: ports: - port: 80 protocol: TCP targetPort: 80 selector: app: nginx-ds sessionAffinity: None type: ClusterIP 声明式创建service资源 ~]# kubectl create -f nginx-ds-svc.yaml ~]# kubectl delete svc nginx-ds ~]# kubectl delete -f nginx-dp-svc.yaml