本文內容
- 主要對K8s 的安裝做記錄
- 安裝前,請準備兩臺以上的linux服務器,且都已經安裝好docker了
- 安裝大致步驟
- 安裝 kubectl
- 安裝 minikube
- 啓動可視化界面 dashboard
安裝 kubectl
-
下載 kubectl
- 下載最新的穩定版本
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
- 常用版本下載
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl
-
添加執行權限
chmod +x ./kubectl
-
使其在全局都可執行
sudo mv ./kubectl /usr/local/bin/kubectl
安裝 minikube
- 下載minikube
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
- 使其在全局都可執行
mv minikube /usr/local/bin/
minikube 不可以使用 root 用戶執行
- 添加用戶
$ useradd test $ echo 1234 | passwd test --stdin $ visudo # 將用戶添加到 sudo 文件中,就可以使用 sudo 進行授權執行高權限命令了 # 改成下面這樣 root ALL=(ALL) ALL test ALL=(ALL) ALL
- 將用戶 添加到 root組
$ usermod -aG root test
- 將用戶添加到 docker組
$ sudo usermod -aG docker test && newgrp docker
啓動 minikube
- 進入 test 用戶
$ su test
- 使用國內的docker鏡像源啓動 minikube
$ minikube start --image-mirror-country='cn' --registry-mirror=https://registry.docker-cn.com --driver=docker
- 查看是否安裝成功
$ minikube status type: Control Pline host: Running kubelet: Running kubeconfig: Configured
- 查看k8s節點
$ kubectl get nodes NAME STATUS ROLES AGE VERSION minikube Ready master 73m v1.18.3
- 創建部署文件,deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: selector: matchLabels: run: load-balancer-example replicas: 2 template: metadata: labels: run: load-balancer-example spec: containers: - name: hello-world image: registry.cn-hangzhou.aliyuncs.com/aliyun_google/google-sample-node-hello:1.0 ports: - containerPort: 8080 protocol: TCP
- 在該文件的目錄下執行命令,部署hello-world
$ kubectl apply -f deployment.yaml
- 暴露端口
$ kubectl expose deployment hello-world --type=NodePort --name=node-service
- 查看訪問的地址
$ minikube service list 或者 $ minikube service node-service --url
- 出現
Hello Kubernetes!
啓動 dashboard
-
minikube dashboard
-
報錯如下
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11 Running without a11y support! Error: no DISPLAY environment variable specified
- 因爲linux除ubuntu外沒有瀏覽器,所以需要加上
--url
- 即
minikube dashboard --url
- 因爲linux除ubuntu外沒有瀏覽器,所以需要加上
-
默認地址只能是 本機地址,暴露地址
1.1.1.1 是服務器的地址 8888 是訪問端口
nohup kubectl proxy --port=8888 --address='1.1.1.1' --accept-hosts='^1.1.1.1$' >/dev/null 2>&1&
- 參考https://www.jianshu.com/p/ef020fa8ca97
-
界面展示