LoginSignup
4
0

More than 3 years have passed since last update.

minikube と nginx でKubernetesを試してみる

Posted at

minikube とは

Kubernetes環境を単一ノードで手軽に動かせるコマンドです。
インストールも手軽で、GKEなどクラウド上に載せる前にローカル環境下でテストが行えるので、
非常に便利です。今回は、Mac環境での動かし方になります。
とても簡単なものですが、軽く挙動を確認したい方はご覧ください!

インストール

minikubeをインストールしていきます。

$ brew cask install minikube

起動

まずminikubeを起動してみましょう。

$ minikube start

Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.

これで起動が完了しました。

ざっくりymlファイル作成

Podを作成するファイル

今回は二つポッドを作成してみます。

nginx-deploy.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
          name: nginx

Serviceを定義するファイル

nginx-service.yml
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - name: nginx
    protocol: TCP
    port: 80
  type: LoadBalancer
  selector:
    app: nginx

ymlファイルを元にPodとServiceを定義していきます。

$ kubectl create -f nginx-deploy.yml
deployment "nginx" created
$ kubectl create -f nginx-service.yml
service "nginx" created
$ minikube service nginx

最後のコマンドを打ちますと、
nginxの初期ページが表示されると思いますので、
確認してみてください。

Welcome_to_nginx_.png

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