LoginSignup
5

More than 3 years have passed since last update.

MacでKubernetesの環境構築

Last updated at Posted at 2019-11-27

前書き

K8sの勉強メモとして残します
k8sの中、比較的に敷居低いminikubeを使用します
公式サイト

インストール

UNADJUSTEDNONRAW_thumb_36.jpg

Get Startedボタンをクリックして、macosを選択してください2019-11-27 16.23のイメージ.jpg

インストールの方法は二つがありまして、どれを選んでも大丈夫です。

brew install minikube
or
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 \
  && sudo install minikube-darwin-amd64 /usr/local/bin/minikube

インストール終了後、ターミナルでminikubeを実行すると、以下の出力が確認できるはずです

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

Basic Commands:
  start          Starts a local kubernetes cluster
  status         Gets the status of a local kubernetes cluster
  stop           Stops a running local kubernetes cluster
  delete         Deletes a local kubernetes cluster
  dashboard      Access the kubernetes dashboard running within the minikube cluster

Images Commands:
  docker-env     Sets up docker env variables; similar to '$(docker-machine env)'
  cache          Add or delete an image from the local cache.

Configuration and Management Commands:
  addons         Modify minikube's kubernetes addons
  config         Modify minikube config
  profile        Profile gets or sets the current minikube profile
  update-context Verify the IP address of the running cluster in kubeconfig.

Networking and Connectivity Commands:
  service        Gets the kubernetes URL(s) for the specified service in your local cluster
  tunnel         tunnel makes services of type LoadBalancer accessible on localhost

...
省略

minikubeのバージョンも確認できます

$ minikube version
minikube version: v1.5.2
commit: 792dbf92a1de583fcee76f8791cff12e0c9440ad-dirty

minikubeサービススタート

minikube start でサービス立ち上げ可能ですが、その前にvirtralBoxがインストールされてることを確認してください
virtralBox公式サイト

なぜvirtralBoxが必要なのか、minikubeの本質がminikubeのサービスを維持するためのコンテナが多数実行してる仮想マシンのようなものです


minikube start --vm-driver=virtualbox

--vm-driver=virtualbox つけない場合 hyperkitで起動することになります

スタート実行し終了後、minikube ssh実行すれば以下のものが確認できるはずです

$ minikube ssh
                         _             _            
            _         _ ( )           ( )           
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __  
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

kubectlインストール

kubectlは何でしょうか、簡単に言うと、Kubernetesコマンドラインツールです

公式サイト

以下のコマンドでインストールできます

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/darwin/amd64/kubectl

インストール終了後、移動して、実行可能な権限を与えます

mv kubectl /usr/local/bin
sudo chmod +x /usr/local/bin/kubectl

その後、kubectlのバージョンを確認してみましょう、以下の出力確認できたらオーケーです

~ $ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:09:08Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}

以上、環境構築終わりました

webでminibukeを確認

minikube dashboard

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5