Kubernetes集群命令行工具kube_ctl 常用命令
kubectl是Kubernetes集群的命令行工具,通过kubectl能够对集群本身进行管理,并能够在集群上进行容器化应用的安装部署。
1、配置kubectl 命令自动补全
[root@k8s-master ~]#source <(kubectl completion bash)
2、K8S集群创建好后查看集群信息
[root@k8s-master ~]# kubectl cluster-info
Kubernetes master is running at https://10.0.0.15:6443
KubeDNS is running at https://10.0.0.15:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@k8s-master ~]#
3、查看deployment资源的详细信息
[root@k8s-master ~]# kubectl describe deployment test-nginx
4、deployment 扩容
[root@k8s-master ~]# kubectl scale deployment --replicas=2 test-nginx
deployment.apps/test-nginx scaled
5、通过kubectl命令行创建deployment
[root@k8s-master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --dry-run=true
nginx-deploy
:是我们创建 deployment 的名字
--image
: 指定使用的镜像
--port=80
:容器暴露的端口,该端口只能在 K8S 集群中访问
-dry-run=true
: 检测语法是否错误,不会正式创建
6、通过Kubectl命令行创建service
[root@k8s-master ~]# kubectl expose deployment nginx-deploy --name=nginx --port=80 --protocol=TCP
service/nginx exposed
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP