0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rocky Linux 9にMicroK8sをインストールする

Last updated at Posted at 2025-03-22

What's?

Rocky Linux 9にMicroK8sをインストールしてみよう、ということで。

MicroK8s

MicroK8sは、Canonicalが開発している軽量なKubernetesディストリビューションです。

特徴としては、以下あたりです。

  • クラスタが構成できる
  • 厳格な分離が可能
  • 自動化されたクラスタ作成・管理
  • NVIDIA GPUのサポート
  • カスタムの起動構成が可能
  • アドオン

個人的にはアドオンが魅力的で、コンテナイメージのレジストリやダッシュボードなど様々なアドオンが利用できます。

MicroK8sは様々なOSにインストールできますが、Linuxであればsnapパッケージとして簡単にインストールできます。

今回はこのMicroK8sをRocky Linux 9にインストールしたいと思います。

環境

今回の環境はこちら。

$ cat /etc/redhat-release
Rocky Linux release 9.5 (Blue Onyx)


$ uname -srvmpio
Linux 5.14.0-503.33.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Mar 19 16:23:31 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Rocky Linux 9にMicroK8sをインストールする

それでは、Rocky Linux 9にMicroK8sをインストールします。

手順としては、こちらに沿っていくことになりますね。

Ubuntu Linuxのようなあらかじめsnapが導入されているディストリビューションはであればいいのですが、そうでない場合はまずsnapのインストールから行います。

$ sudo dnf install snapd
$ sudo systemctl enable --now snapd.socket
$ sudo ln -s /var/lib/snapd/snap /snap

そしてMicroK8sをインストール。--classicをつけてインストールする、classic snapになります。

$ sudo snap install microk8s --classic

注意点として、Rocky Linux 9の場合はsnapをインストールする時に最後のsudo ln -s /var/lib/snapd/snap /snapが必要で、これがないとclass snapのインストールに失敗します。

$ sudo snap install microk8s --classic
error: too early for operation, device not yet seeded or device model not acknowledged

インストールしたら、ユーザーのグループ参加と$HOME/.kubeディレクトリの作成を行います。

$ sudo usermod -a -G microk8s $USER
$ mkdir -p ~/.kube
$ chmod 0700 ~/.kube

ここまでできたら、シェルに再ログインします。

すると、microk8sコマンドが使えるようになっています。

$ microk8s version
MicroK8s v1.32.2 revision 7731

ステータスを確認。

$ microk8s status --wait-ready
microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    dns                  # (core) CoreDNS
    ha-cluster           # (core) Configure high availability on the current node
    helm                 # (core) Helm - the package manager for Kubernetes
    helm3                # (core) Helm 3 - the package manager for Kubernetes
  disabled:
    cert-manager         # (core) Cloud native certificate management
    cis-hardening        # (core) Apply CIS K8s hardening
    community            # (core) The community addons repository
    dashboard            # (core) The Kubernetes dashboard
    gpu                  # (core) Alias to nvidia add-on
    host-access          # (core) Allow Pods connecting to Host services smoothly
    hostpath-storage     # (core) Storage class; allocates storage from host directory
    ingress              # (core) Ingress controller for external access
    kube-ovn             # (core) An advanced network fabric for Kubernetes
    mayastor             # (core) OpenEBS MayaStor
    metallb              # (core) Loadbalancer for your Kubernetes cluster
    metrics-server       # (core) K8s Metrics Server for API access to service metrics
    minio                # (core) MinIO object storage
    nvidia               # (core) NVIDIA hardware (GPU and network) support
    observability        # (core) A lightweight observability stack for logs, traces and metrics
    prometheus           # (core) Prometheus operator for monitoring and logging
    rbac                 # (core) Role-Based Access Control for authorisation
    registry             # (core) Private image registry exposed on localhost:32000
    rook-ceph            # (core) Distributed Ceph storage using Rook
    storage              # (core) Alias to hostpath-storage add-on, deprecated

kubectlコマンドを使ってみます。

$ microk8s kubectl get nodes
NAME            STATUS   ROLES    AGE   VERSION
rocky9-server   Ready    <none>   60s   v1.32.2

microk8s kubectlという指定方法になるのですが、これが面倒な場合は以下のようにエイリアスをつけましょう。

$ alias kubectl='microk8s kubectl'

ちなみにチュートリアルではService間の通信に使うのでdnsアドオンを有効化することが推奨されていましたが

To start it is recommended to add DNS management to facilitate communication between services.

先ほどステータスを見ると、すでに有効化されていましたね。

addons:
  enabled:
    dns                  # (core) CoreDNS

実際、さらに有効化しようとしても、「すでに有効になっている」と言われます。

$ microk8s enable dns
Infer repository core for addon dns
Addon core/dns is already enabled

コンテナを動かしてみます。

$ microk8s kubectl create deployment nginx --image=nginx
deployment.apps/nginx created

nginxが動いています。

$ microk8s kubectl get all
NAME                         READY   STATUS    RESTARTS   AGE
pod/nginx-5869d7778c-48r8c   1/1     Running   0          31s

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.152.183.1   <none>        443/TCP   3m28s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx   1/1     1            1           31s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-5869d7778c   1         1         1       31s

動作確認のために、Serviceを作成。

$ microk8s kubectl expose deployment nginx --port 80


$ microk8s kubectl get service nginx
NAME    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
nginx   ClusterIP   10.152.183.125   <none>        80/TCP    36s

curlでアクセス。

$ curl 10.152.183.125
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

OKですね。

では、ラベルを確認して

$ microk8s kubectl get all --show-labels
NAME                         READY   STATUS    RESTARTS   AGE     LABELS
pod/nginx-5869d7778c-48r8c   1/1     Running   0          2m52s   app=nginx,pod-template-hash=5869d7778c

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE     LABELS
service/kubernetes   ClusterIP   10.152.183.1     <none>        443/TCP   5m49s   component=apiserver,provider=kubernetes
service/nginx        ClusterIP   10.152.183.125   <none>        80/TCP    104s    app=nginx

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE     LABELS
deployment.apps/nginx   1/1     1            1           2m52s   app=nginx

NAME                               DESIRED   CURRENT   READY   AGE     LABELS
replicaset.apps/nginx-5869d7778c   1         1         1       2m52s   app=nginx,pod-template-hash=5869d7778c

削除。

$ microk8s kubectl delete all -l app=nginx
pod "nginx-5869d7778c-48r8c" deleted
service "nginx" deleted
deployment.apps "nginx" deleted
replicaset.apps "nginx-5869d7778c" deleted

オマケ

少し追加でコマンドを。

MicroK8sの起動と停止。

$ microk8s start


$ microk8s stop

MicroK8sをデフォルトの状態に戻すにはmicrok8s resetを実行します。

$ microk8s reset

これでリソースが削除されるはずなのですが…

$ microk8s reset
Elevated permissions is needed for this operation. Please run this command with sudo.

実際に実行すると、sudoをつけなさいと言われます。

そしてsudoをつけると、今度はコマンドが見つかりませんと言われます。

$ sudo microk8s reset
sudo: microk8s: コマンドが見つかりません

というわけで、実際に実行するならこうですね。

$ sudo $(which microk8s) reset

ちなみにmicrok8s resetした後にステータスを見ると、なぜかdnsアドオンは有効になっていませんでした…。

$ microk8s status --wait-ready
microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    ha-cluster           # (core) Configure high availability on the current node
    helm                 # (core) Helm - the package manager for Kubernetes
    helm3                # (core) Helm 3 - the package manager for Kubernetes
  disabled:
    cert-manager         # (core) Cloud native certificate management
    cis-hardening        # (core) Apply CIS K8s hardening
    community            # (core) The community addons repository
    dashboard            # (core) The Kubernetes dashboard
    dns                  # (core) CoreDNS
    gpu                  # (core) Alias to nvidia add-on
    host-access          # (core) Allow Pods connecting to Host services smoothly
    hostpath-storage     # (core) Storage class; allocates storage from host directory
    ingress              # (core) Ingress controller for external access
    kube-ovn             # (core) An advanced network fabric for Kubernetes
    mayastor             # (core) OpenEBS MayaStor
    metallb              # (core) Loadbalancer for your Kubernetes cluster
    metrics-server       # (core) K8s Metrics Server for API access to service metrics
    minio                # (core) MinIO object storage
    nvidia               # (core) NVIDIA hardware (GPU and network) support
    observability        # (core) A lightweight observability stack for logs, traces and metrics
    prometheus           # (core) Prometheus operator for monitoring and logging
    rbac                 # (core) Role-Based Access Control for authorisation
    registry             # (core) Private image registry exposed on localhost:32000
    rook-ceph            # (core) Distributed Ceph storage using Rook
    storage              # (core) Alias to hostpath-storage add-on, deprecated

最後はアンインストール方法です。snap removeで削除します。

$ sudo snap remove microk8s
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?