版本
名称 | 版本 | 说明 |
---|---|---|
阿里云集群版本 | 1.20.6 | |
腾讯云集群版本 | 1.20.6 | |
kubectl | 1.20 | |
Kind | 0.12.0 | 本地集群环境搭建 |
安装启动
kubectl
下载对应版本
$ curl -LO "https://dl.k8s.io/release/v1.20.0/bin/darwin/amd64/kubectl"
添加可执行权限
$ chmod +x ./kubectl
将二进制文件移动到系统目录
$ sudo mv ./kubectl /usr/local/bin/kubectl
$ sudo chown root: /usr/local/bin/kubectl
Kind
通过go安装
$ go install sigs.k8s.io/kind@v0.12.0
本机启动集群
$ kind create cluster
Creating cluster "kind" ...
Ensuring node image (kindest/node:v1.23.4)
Preparing nodes
Writing configuration
Starting control-plane
Installing CNI
Installing StorageClass
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community
查看信息
$ kubectl cluster-info --context kind-kind
Kubernetes control plane is running at https://127.0.0.1:63736
CoreDNS is running at https://127.0.0.1:63736/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
通过kubectl命令行查看kind启动服务端的版本信息
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:59:43Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.4", GitCommit:"e6c093d87ea4cbb530a7b2ae91e54c0842d8308a", GitTreeState:"clean", BuildDate:"2022-03-06T21:32:53Z", GoVersion:"go1.17.7", Compiler:"gc", Platform:"linux/amd64"}
常用命令
申请配置,创建或更新资源
$ kubectl apply -f user.config.yaml
查看服务
$ kubectl get svc
查看服务详情
kubectl describe service {$serverName}
查看部署
$ kubectl get deployments
查看pods
$ kubectl get pods
查看 pods 详情
$ kubectl describe pod {$podName}
调整副本数
$ kubectl scale --replicas=3 user.deployment.yaml
删除pod
$ kubectl delete pod {$podName}
查看日志
$ kubectl logs -f {$podName}
集群连接
本地集群连接
通过kind获取本地集群配置输出到指定的目录中
$ kind get kubeconfig > ~/Work/K8s/king.config
通过vs code Set Kubeconfig 连接本地 kind
远程集群连接
通过命令设置配置
# 设置变量
$ export KUBECONFIG=~/Work/K8s/king.config
# 查看集群状态
$ kubectl cluster-info
# 清除配置
$ unset KUBECONFIG