Minikubeのコマンド
| コマンド | 操作 |
|---|---|
| minikube <command> –help (または -h) | Use “minikube <command> –help” for more information about a given command. |
| minikube ssh | Log into or run a command on a machine with SSH. |
| minikube ip | Retrieves the IP address of the specified node, and writes it to STDOUT. |
| minikube profile list | Lists all valid minikube profiles and detects all possible invalid profiles. |
| minikube status | Gets the status of a local Kubernetes cluster. |
| minikube start | Starts a local Kubernetes cluster |
| minikube stop | Stops a local Kubernetes cluster. This command stops the underlying VM or container, but keeps user data intact. The cluster can be started again with the “start” command. |
| minikube delete | Deletes a local Kubernetes cluster. This command deletes the VM, and removes all associated files. |
| minikube node add | Adds a node to the given cluster config, and starts it. |
| minikube addons list | Lists all available minikube addons as well as their current statuses (enabled/disabled) |
| minikube service | Returns the Kubernetes URL(s) for service(s) in your local cluster. In the case of multiple URLs they will be printed one at a time. |
| minikube service list | Lists the URLs for the services in your local cluster |
| minikube tunnel | tunnel creates a route to services deployed with type LoadBalancer and sets their Ingress to their ClusterIP. |
kubectlのコマンド
pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs)
| コマンド | 操作 |
|---|---|
| kubectl <command> –help (または -h) | Use “kubectl <command> –help” for more information about a given command. |
| kubectl version | Print the client and server version information for the current context. |
| kubectl get <resource_name> | Display one or many resources. |
| kubectl describe <resource_name> | Show details of a specific resource or group of resources. |
| kubectl create deployment my-dep –image=nginx –replicas=3 | Create a deployment named my-dep that runs the nginx image with 3 replicas |
| kubectl create -f <filename> | |
| kubectl edit deployment my-dep | |
| kubectl logs <pod_name> | Print the logs for a container in a pod or specified resource. |
| kubectl exec -it <pod_name> — /bin/bash | Execute a command in a container. |
| kubectl delete deployment <deployment_name> | |
| kubectl apply -f <file_name> | Apply a configuration to a resource by file name or stdin. |
| kubectl expose <resource_name> kubectl expose deployment my-nginx –type=NodePort –port=8080 | Expose a resource as a new Kubernetes service. |
| kubectl scale –replicas=<n> | Set a new size for a deployment, replica set, replication controller, or stateful set. |
| kubectl port-forward <pod_name> 5000 kubectl port-forward <pod_name> 8888:5000 | Forward one or more local ports to a pod. |
kubectlチートシート:https://kubernetes.io/ja/docs/reference/kubectl/cheatsheet/
アプリケーションのデプロイ
Dockerfileからイメージをビルドする
docker image build -t <app_image_name:tag> .
kubectl create -f ./<yaml_file_to_create_pod_for_app>
kubectl get pods
<yaml_file_to_create_pod_for_app>の内容
- imagePullPolicyなしの場合、STATUSは「ErrImagePull」になる
- imagePullPolicy: Neverの場合、STATUSは「ImagePullBackOff」になる
kubectl describe pod
シェルをMinikubeのDockerデーモンに向ける
eval $(minikube -p minikube docker-env)
注:上記のevalコマンドが効かない場合、下記のdocker image buildコマンドの代わりに「minikube image build -t <app_image_name:tag> .」でもイメージをビルドできる
docker image build -t <app_image_name:tag> .
<yaml_file_to_create_pod_for_app>に「imagePullPolicy: Never」を追記する
kubectl create -f <yaml_file_to_create_pod_for_app>
kubectl get pods
STATUSが「Running」になっている
Minikube内でアプリを実行する
kubectl exec -it <app_name> -- /bin/bash
curl http://127.0.0.1:5000/
exit
サーバからアプリを実行する
kubectl port-forward <app_pod_name> 5000
curl http://127.0.0.1:5000/
#kubectl #Kubernetes #Minikube