使用minikube快速部署k8s集群


1. 安裝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 && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

  下載指定版本,例如下載v1.9.0版本

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

  

2. 安裝minikube

minikube的源碼地址:https://github.com/kubernetes/minikube

2.1 安裝minikube

以下命令為安裝latest版本的minikube

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

  

安裝指定版本可到https://github.com/kubernetes/minikube/releases下載對應版本。

例如:以下為安裝v0.28.2版本

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.28.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

2.2 minikube命令幫助

Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows.

Usage:
  minikube [command]

Available Commands:
  addons           Modify minikube's kubernetes addons
  cache            Add or delete an image from the local cache.
  completion       Outputs minikube shell completion for the given shell (bash or zsh)
  config           Modify minikube config
  dashboard        Opens/displays the kubernetes dashboard URL for your local cluster
  delete           Deletes a local kubernetes cluster
  docker-env       Sets up docker env variables; similar to '$(docker-machine env)'
  get-k8s-versions Gets the list of Kubernetes versions available for minikube when using the localkube bootstrapper
  ip               Retrieves the IP address of the running cluster
  logs             Gets the logs of the running localkube instance, used for debugging minikube, not user code
  mount            Mounts the specified directory into minikube
  profile          Profile sets the current minikube profile
  service          Gets the kubernetes URL(s) for the specified service in your local cluster
  ssh              Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'
  ssh-key          Retrieve the ssh identity key path of the specified cluster
  start            Starts a local kubernetes cluster
  status           Gets the status of a local kubernetes cluster
  stop             Stops a running local kubernetes cluster
  update-check     Print current and latest version number
  update-context   Verify the IP address of the running cluster in kubeconfig.
  version          Print the version of minikube

Flags:
      --alsologtostderr                  log to standard error as well as files
  -b, --bootstrapper string              The name of the cluster bootstrapper that will set up the kubernetes cluster. (default "localkube")
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory
      --loglevel int                     Log level (0 = DEBUG, 5 = FATAL) (default 1)
      --logtostderr                      log to standard error instead of files
  -p, --profile string                   The name of the minikube VM being used.
    This can be modified to allow for multiple minikube instances to be run independently (default "minikube")
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
  -v, --v Level                          log level for V logs
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

Use "minikube [command] --help" for more information about a command.

3. 使用minikube安裝k8s集群

3.1. minikube start

可以以Docker的方式運行k8s的組件,但需要先安裝Docker(可參考Docker安裝),啟動參數使用--vm-driver=none

minikube start --vm-driver=none

  

安裝指定版本的kubernetes集群

# 查閱版本
minikube get-k8s-versions
# 選擇版本啟動
minikube start --kubernetes-version v1.7.3 --vm-driver=none

  

3.2. minikube status

$ minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 172.16.94.139

  

3.3. minikube stop
minikube stop 命令可以用來停止集群。 該命令會關閉 minikube 虛擬機,但將保留所有集群狀態和數據。 再次啟動集群將恢復到之前的狀態。

3.4. minikube delete
minikube delete 命令可以用來刪除集群。 該命令將關閉並刪除 minikube 虛擬機。沒有數據或狀態會被保存下來。

4. 查看部署結果
4.1. 部署組件

navy@Deepin:~# kubectl get all --namespace=kube-system
NAME                                        READY     STATUS    RESTARTS   AGE
pod/etcd-minikube                           1/1       Running   0          38m
pod/kube-addon-manager-minikube             1/1       Running   0          38m
pod/kube-apiserver-minikube                 1/1       Running   1          39m
pod/kube-controller-manager-minikube        1/1       Running   0          38m
pod/kube-dns-86f4d74b45-bdfnx               3/3       Running   0          38m
pod/kube-proxy-dqdvg                        1/1       Running   0          38m
pod/kube-scheduler-minikube                 1/1       Running   0          38m
pod/kubernetes-dashboard-5498ccf677-c2gnh   1/1       Running   0          38m
pod/storage-provisioner                     1/1       Running   0          38m

NAME                           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
service/kube-dns               ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP   38m
service/kubernetes-dashboard   NodePort    10.104.48.227   <none>        80:30000/TCP    38m

NAME                        DESIRED   CURRENT   READY     UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/kube-proxy   1         1         1         1            1           <none>          38m

NAME                                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/kube-dns               1         1         1            1           38m
deployment.apps/kubernetes-dashboard   1         1         1            1           38m

NAME                                              DESIRED   CURRENT   READY     AGE
replicaset.apps/kube-dns-86f4d74b45               1         1         1         38m
replicaset.apps/kubernetes-dashboard-5498ccf677   1         1         1         38m

  

4.2. dashboard

通過訪問ip:port,例如:http://172.16.94.139:30000/,可以訪問k8s的dashboard控制台。

 

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM