
ショコラ
minikube で hello-minikube を動かすには?(マニュフェストファイル有り)
https://kubernetes.io/ja/docs/tutorials/hello-minikube/ をベースに、hello-minikube を実行しましたが、今回はマニュフェストファイルを作って実行してみたいと思います。
「コマンドからマニュフェストを生成する方法」がありましたので、こちらを使ってみたいと思います。

もっさん先輩
kubectlコマンドの後に↓のオプションを追加すると、マニュフェストを生成できます。
--dry-run -o yaml
例
kubectlコマンドから、マニュフェストを生成します。
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 --dry-run -o yaml
$ kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 --dry-run -o yaml
W0831 22:29:11.217626 122065 helpers.go:636] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: hello-minikube
name: hello-minikube
spec:
replicas: 1
selector:
matchLabels:
app: hello-minikube
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: hello-minikube
spec:
containers:
- image: k8s.gcr.io/echoserver:1.4
name: echoserver
resources: {}
status: {}
手順
minikube で hello-minikube を マニュフェストファイル で動かす手順。
- minikube を起動します。
minikube start
- デプロイメントのマニュフェストを生成します。
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 --dry-run -o yaml
$ kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 --dry-run -o yaml
W0831 22:29:11.217626 122065 helpers.go:636] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: hello-minikube
name: hello-minikube
spec:
replicas: 1
selector:
matchLabels:
app: hello-minikube
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: hello-minikube
spec:
containers:
- image: k8s.gcr.io/echoserver:1.4
name: echoserver
resources: {}
status: {}
- デプロイメントを公開するサービスのマニュフェストを生成します。
kubectl expose deployment hello-minikube --type=NodePort --port=8080 --dry-run -o yaml
$ kubectl expose deployment hello-minikube --type=NodePort --port=8080 --dry-run -o yaml
W0831 22:31:49.193883 124101 helpers.go:636] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: hello-minikube
name: hello-minikube
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
app: hello-minikube
type: NodePort
status:
loadBalancer: {}
- 2つを合わせてマニュフェストファイルを作成します。
デプロイメントのマニュフェスト と サービスのマニュフェスト を「—」で結合します。
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: hello-minikube
name: hello-minikube
spec:
replicas: 1
selector:
matchLabels:
app: hello-minikube
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: hello-minikube
spec:
containers:
- image: k8s.gcr.io/echoserver:1.4
name: echoserver
resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: hello-minikube
name: hello-minikube
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
app: hello-minikube
type: NodePort
status:
loadBalancer: {}
- ローカルkubernetesクラスタに反映します。
kubectl apply -f hello-minikube.yaml
$ kubectl apply -f hello-minikube.yaml
deployment.apps/hello-minikube created
service/hello-minikube created
- サービスにアクセスできるようにします。(おまじない)
minikube service hello-minikube
↑の おまじない を実行したところ、↓ブラウザが立ち上がり情報が表示されました。

以上