Minikube のインストール手順

2022/09/18に公開

この記事について

Kubernetes の学習を開始するにあたり Ubuntu 22.04 desktop 上に実習環境として Minikube 環境を作成したときの備忘録です。この記事では触れませんが、VS Code[1] をインストールしておくと、オブジェクトの定義ファイル等を書くときに便利かと思います。

手順

  1. Oracle VritualBox をインストール
  2. kubectl をインストール
  3. Minikube をインストール

インストール

Oracle VirtualBox をインストール

  1. Oracle VirtualBox の Linux 用パッケージのダウンロードサイト [2] から Ubuntu 22.04 用のパッケージをダウンロード
  2. Oracle VirtualBox のダウンロードサイト [3] から Oracle VM VirtualBox Extension Pack をダウンロード
  3. ダウンロードしたパッケージをインストール
  4. Oracle VM VirtualBox マネージャーを起動し、 [ファイル(F)] → [環境設定(P)...] → [機能拡張] から Oracle VM VirtualBox Extension Pack をインストール

kubectl をインストール

Install and Set Up kubectl on Linux [4] にいくつかの方法が説明されています。今回は snap コマンド [5] でインストールします。

snap install kubectl --classic
kubectl version --client

Minikube をインストール

minikube start [6]に記載されている手順に従って Minikube をインストールします。

sudo apt -y install curl
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
minikube start --driver=virtualbox

Minikube を起動/停止

起動

Minikube を起動します。

minikube start

停止

Minikube を停止します。

minikube stop

動作確認

Kubernetes のチュートリアルである Hello Minikube [7] を使用し、インストールした Minikube の動作を確認します。

Deployment の作成と確認

kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
kubectl get deployments
kubectl get pods
kubectl get events
kubectl config view

Service の作成と確認

kubectl expose deployment hello-node --type=LoadBalancer --port=8080
kubectl get services
minikube service hello-node --url

ブラウザーで確認

表示された URL をブラウザーで表示

クリーンアップ

作成した Service と Deployment を削除します。

kubectl delete service hello-node
kubectl delete deployment hello-node
kubectl get all

動作確認の実行ログ

Deployment の作成と確認

y_mrok@minikube:~$ kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
deployment.apps/hello-node created
y_mrok@minikube:~$ kubectl get deployments
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
hello-node   1/1     1            1           8s
y_mrok@minikube:~$ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
hello-node-697897c86-xk2d7   1/1     Running   0          17s
y_mrok@minikube:~$ kubectl get events
LAST SEEN   TYPE      REASON                    OBJECT                             MESSAGE
24s         Normal    Scheduled                 pod/hello-node-697897c86-xk2d7     Successfully assigned default/hello-node-697897c86-xk2d7 to minikube
21s         Normal    Pulling                   pod/hello-node-697897c86-xk2d7     Pulling image "k8s.gcr.io/echoserver:1.4"
19s         Normal    Pulled                    pod/hello-node-697897c86-xk2d7     Successfully pulled image "k8s.gcr.io/echoserver:1.4" in 1.743628947s
19s         Normal    Created                   pod/hello-node-697897c86-xk2d7     Created container echoserver
18s         Normal    Started                   pod/hello-node-697897c86-xk2d7     Started container echoserver
24s         Normal    SuccessfulCreate          replicaset/hello-node-697897c86    Created pod: hello-node-697897c86-xk2d7
18m         Normal    Scheduled                 pod/hello-node-7f48bfb94f-24q8n    Successfully assigned default/hello-node-7f48bfb94f-24q8n to minikube
18m         Normal    Pulling                   pod/hello-node-7f48bfb94f-24q8n    Pulling image "registry.k8s.io/echoserver:1.4"
17m         Normal    Pulled                    pod/hello-node-7f48bfb94f-24q8n    Successfully pulled image "registry.k8s.io/echoserver:1.4" in 22.270876625s
17m         Normal    Created                   pod/hello-node-7f48bfb94f-24q8n    Created container echoserver
17m         Normal    Started                   pod/hello-node-7f48bfb94f-24q8n    Started container echoserver
13m         Normal    Killing                   pod/hello-node-7f48bfb94f-24q8n    Stopping container echoserver
13m         Warning   FailedKillPod             pod/hello-node-7f48bfb94f-24q8n    error killing pod: failed to "KillContainer" for "echoserver" with KillContainerError: "rpc error: code = Unknown desc = Error response from daemon: No such container: 818671de73f37bb9d936f33cb41674253a99095e23b5ac21f6edc2b508d11874"
18m         Normal    SuccessfulCreate          replicaset/hello-node-7f48bfb94f   Created pod: hello-node-7f48bfb94f-24q8n
18m         Normal    ScalingReplicaSet         deployment/hello-node              Scaled up replica set hello-node-7f48bfb94f to 1
24s         Normal    ScalingReplicaSet         deployment/hello-node              Scaled up replica set hello-node-697897c86 to 1
33m         Normal    NodeHasSufficientMemory   node/minikube                      Node minikube status is now: NodeHasSufficientMemory
33m         Normal    NodeHasNoDiskPressure     node/minikube                      Node minikube status is now: NodeHasNoDiskPressure
33m         Normal    NodeHasSufficientPID      node/minikube                      Node minikube status is now: NodeHasSufficientPID
33m         Normal    Starting                  node/minikube                      Starting kubelet.
33m         Normal    NodeHasSufficientMemory   node/minikube                      Node minikube status is now: NodeHasSufficientMemory
33m         Normal    NodeHasNoDiskPressure     node/minikube                      Node minikube status is now: NodeHasNoDiskPressure
33m         Normal    NodeHasSufficientPID      node/minikube                      Node minikube status is now: NodeHasSufficientPID
33m         Normal    NodeAllocatableEnforced   node/minikube                      Updated Node Allocatable limit across pods
33m         Normal    RegisteredNode            node/minikube                      Node minikube event: Registered Node minikube in Controller
33m         Normal    NodeReady                 node/minikube                      Node minikube status is now: NodeReady
33m         Normal    Starting                  node/minikube                      
6m32s       Normal    Starting                  node/minikube                      Starting kubelet.
6m31s       Normal    NodeHasSufficientMemory   node/minikube                      Node minikube status is now: NodeHasSufficientMemory
6m31s       Normal    NodeHasNoDiskPressure     node/minikube                      Node minikube status is now: NodeHasNoDiskPressure
6m31s       Normal    NodeHasSufficientPID      node/minikube                      Node minikube status is now: NodeHasSufficientPID
6m32s       Normal    NodeAllocatableEnforced   node/minikube                      Updated Node Allocatable limit across pods
5m50s       Normal    RegisteredNode            node/minikube                      Node minikube event: Registered Node minikube in Controller
5m39s       Normal    Starting                  node/minikube                      
y_mrok@minikube:~$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/y_mrok/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Sat, 17 Sep 2022 23:41:09 JST
        provider: minikube.sigs.k8s.io
        version: v1.27.0
      name: cluster_info
    server: https://192.168.59.100:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Sat, 17 Sep 2022 23:41:09 JST
        provider: minikube.sigs.k8s.io
        version: v1.27.0
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/y_mrok/.minikube/profiles/minikube/client.crt
    client-key: /home/y_mrok/.minikube/profiles/minikube/client.key
y_mrok@minikube:~$ 

Service の作成と確認

y_mrok@minikube:~$ kubectl expose deployment hello-node --type=LoadBalancer --port=8080
service/hello-node exposed
y_mrok@minikube:~$ kubectl get services
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.110.161.133   <pending>     8080:32286/TCP   6s
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP          37m
y_mrok@minikube:~$ minikube service hello-node --url
http://192.168.59.100:32286
y_mrok@minikube:~$ 

ブラウザーで確認

「 Service の作成と確認」で minikube service hello-node --url を実行したときに表示された URL をブラウザーで開くと、次のような内容が表示されます。

CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://192.168.59.100:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
accept-encoding=gzip, deflate
accept-language=ja,en-US;q=0.7,en;q=0.3
connection=keep-alive
dnt=1
host=192.168.59.100:32286
upgrade-insecure-requests=1
user-agent=Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0
BODY:
-no body in request-

クリーンアップ

y_mrok@minikube:~$ kubectl delete service hello-node
service "hello-node" deleted
y_mrok@minikube:~$ kubectl delete deployment hello-node
deployment.apps "hello-node" deleted
y_mrok@minikube:~$ kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   41m
y_mrok@minikube:~$ 

参照させていただいたサイト

https://www.virtualbox.org/wiki/Downloads
https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
https://minikube.sigs.k8s.io/docs/start/
https://kubernetes.io/docs/tutorials/hello-minikube/

脚注
  1. https://azure.microsoft.com/ja-jp/products/visual-studio-code/ ↩︎

  2. https://www.virtualbox.org/wiki/Linux_Downloads ↩︎

  3. https://www.virtualbox.org/wiki/Downloads ↩︎

  4. https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/ ↩︎

  5. https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-other-package-management ↩︎

  6. https://minikube.sigs.k8s.io/docs/start/ ↩︎

  7. https://kubernetes.io/docs/tutorials/hello-minikube/ ↩︎

Discussion