minikube をいじった時のメモ

minikube コマンド

  • minikube 起動: sudo /usr/local/bin/minikube start --vm-driver=none
  • minikube 停止: sudo /usr/local/bin/minikube stop

kubectl コマンド

  • 詳細: https://kubernetes.io/ja/docs/reference/kubectl/cheatsheet/
  • オブジェクト作成: kubectl create -f manifest.yaml
  • オブジェクト更新: kubectl apply -f manifest.yaml --record=true
  • オブジェクト削除: kubectl delete -f manifest.yaml
  • オブジェクト一覧: kubectl get po, kubectl get services
  • オブジェクト詳細: kubectl describe pods my-pod
  • Pod の数を変更する(リソースのスケーリング): kubectl scale --replicas=1 deployment/my-deployment
  • コンテナに入る: kubectl exec -it my-pod -- /bin/bash

コンテナの展開と削除

deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 5 
  selector:
    matchLabels:
      app: my-webapp
  template:
    metadata:
      labels:
        app: my-webapp
    spec:
      containers:
        - name: my-container
          image : nginx 
          ports:
            - containerPort: 80

service.yaml

apiVersion: v1
kind: Service 
metadata:
  name: my-service
spec:
  type: NodePort
  ports:
    - nodePort: 30000 
      port: 8080
      targetPort: 80
      protocol: TCP
  selector:
    app: my-webapp

実行してみる

$ kubectl create -f deploy.yaml -f service.yaml 
deployment.apps/my-deployment created
service/my-service created
$ kubectl get po
NAME                             READY   STATUS    RESTARTS   AGE
my-deployment-69f8f59c57-2hl8f   1/1     Running   0          21s
my-deployment-69f8f59c57-5q8lh   1/1     Running   0          21s
my-deployment-69f8f59c57-hz6ss   1/1     Running   0          21s
my-deployment-69f8f59c57-qqvmc   1/1     Running   0          21s
my-deployment-69f8f59c57-zppw8   1/1     Running   0          21s
$ kubectl delete -f service.yaml -f deploy.yaml
service "my-service" deleted
deployment.apps "my-deployment" deleted