6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Minikubeのインストール

Last updated at Posted at 2019-06-17

CPUの仮想化技術が有効になっているかチェック

$ egrep --color 'vmx|svm' /proc/cpuinfo

必要なパッケージをインストール

$ sudo yum install libvirt libvirt-daemon-kvm qemu-kvm libvirt-client socat

KVMのインストール

$ sudo systemctl enable libvirtd
$ sudo systemctl start libvirtd
$ sudo systemctl status libvirtd
$ sudo virsh net-list | grep default
$ sudo usermod -a -G libvirt $(whoami)
$ newgrp libvirt

Minikubeのインストール

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
$ sudo install minikube /usr/local/bin

デフォルト値の設定

$ minikube config set vm-driver kvm2
$ minikube config set memory 4096
$ minikube config set disk-size 20GB

起動

$ minikube start --kubernetes-version v1.14.8
$ minikube status

kubectlのインストール

$ sudo tee /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
$ sudo yum install kubectl-1.14.8
$ kubectl get pods -A

Ingressのインストール

$ minikube addons enable ingress
$ kubectl get pods -n kube-system | grep ingress

NFSのインストール

$ sudo yum install nfs-utils
$ sudo systemctl enable nfs-server
$ sudo systemctl start nfs-server
$ sudo systemctl status nfs-server

Minikube用の共有ディレクトリの設定

$ sudo mkdir -p /data/minikube
$ sudo chown $(whoami):$(whoami) /data/minikube
$ sudo tee /etc/exports.d/minikube.exports <<EOF
/data/minikube $(minikube ip | cut -d . -f 1-3).0/24(rw,no_root_squash)
EOF
$ sudo exportfs -a
$ showmount -e

MinikubeからNFSへのアクセスを許可

$ sudo firewall-cmd --permanent --new-zone=minikube
$ sudo firewall-cmd --permanent --zone=minikube --set-target=ACCEPT
$ sudo firewall-cmd --permanent --zone=minikube --add-source=$(minikube ip | cut -d . -f 1-3).0/24
$ sudo firewall-cmd --add-service=nfs --zone=minikube --permanent
$ sudo firewall-cmd --reload
$ sudo firewall-cmd --list-all --zone=minikube

PV・PVCの作成

$ tee /tmp/nfs-minikube.yml <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-minikube
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
  nfs:
    server: $(minikube ip | cut -d . -f 1-3).1
    path: "/data/minikube"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs-minikube
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: slow
EOF
$ kubectl apply -f /tmp/nfs-minikube.yml
$ kubectl get pv nfs-minikube
$ kubectl get pvc nfs-minikube

Nginxをデプロイ

$ tee /tmp/nginx.yml <<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: html
      volumes:
        - name: html
          persistentVolumeClaim:
            claimName: nfs-minikube
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - port: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  backend:
    serviceName: nginx
    servicePort: 80
EOF
$ kubectl apply -f /tmp/nginx.yml

動作確認

ページを用意

$ tee /data/minikube/index.html <<EOF
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<div>ようこそ $(whoami) さん</div>
</body>
</html>
EOF

ダッシュボードを開く

$ minikube dashboard &

Ingress のエンドポイントをクリックして別タブに表示されるページを確認

停止

$ minikube stop
$ minikube status

(または)削除

$ minikube delete
$ minikube status
6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?