用k8s搭建一个环境的命令行
时间: 2024-04-30 22:23:04 浏览: 91
以下是用k8s搭建一个环境的命令行:
1. 安装kubectl
```bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
```
2. 安装minikube
```bash
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
```
3. 启动minikube
```bash
minikube start --vm-driver=virtualbox
```
4. 部署一个应用
```bash
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080
```
5. 查看服务
```bash
minikube service hello-minikube --url
```
这个命令将输出应用程序的URL,可以通过Web浏览器访问它。
6. 删除应用
```bash
kubectl delete service hello-minikube
kubectl delete deployment hello-minikube
```
7. 停止minikube
```bash
minikube stop
```
阅读全文