Help us understand the problem. What is going on with this article?

Minikubeのインストール

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

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

KVMのインストール

$ sudo yum install libvirt libvirt-daemon-kvm qemu-kvm libvirt-client
$ 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/v1.3.1/minikube-linux-amd64
$ sudo install minikube /usr/local/bin

KVM2ドライバーのインストール

$ curl -LO https://github.com/kubernetes/minikube/releases/download/v1.3.1/docker-machine-driver-kvm2
$ sudo install docker-machine-driver-kvm2 /usr/local/bin/

デフォルト値の設定

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

起動

$ minikube start
$ 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
$ kubectl get pods -n kube-system | grep minikube

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
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away