2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rancher Desktop で Kubernetes を始める

Posted at

Kubernetes は好きでは無いが仕事で使う事になってしまったので諦めて復習します。

準備

今回は Rancher Desktop という Docker 互換アプリで Kubernetes 環境をローカルに作ります。 Rancher Desktop をインストールすると Kubernetes も起動します。あとは、rancher-desktop に use-context するとローカルの kubernetes が使えるようです。(ドキュメントが見つからなかった)

$ kubectl config use-context rancher-desktop
$ kubectl get namespaces
NAME              STATUS   AGE
kube-system       Active   105d
kube-public       Active   105d
kube-node-lease   Active   105d
default           Active   105d

簡単なアプリをデプロイする。

ここで Run a Stateless Application Using a Deployment の例を試します。

以下のようなファイル deployment.yaml を作って:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
    - name: http
      port: 8087 # 公開するポート番号
      targetPort: 80 # Pod のポート番号

kubectl apply でデプロイします。

$ kubectl apply -f deployment.yaml 
deployment.apps/nginx-deployment created
service/nginx created

$ kubectl get pod     
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-86dcfdf4c6-fcwct   1/1     Running   0          21s
nginx-deployment-86dcfdf4c6-lhrxd   1/1     Running   0          21s

$ kubectl get services
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)          AGE
kubernetes   ClusterIP      10.43.0.1       <none>         443/TCP          106d
nginx        LoadBalancer   10.43.125.223   192.168.5.15   8087:31345/TCP   27s

これで http://localhost:8087 にデプロイされています。

kubectl delete で削除します。

$ kubectl delete -f deployment.yaml
deployment.apps "nginx-deployment" deleted
service "nginx" deleted

これで何とか Kubernetes の実験を始められるのではないかと思います。

参考

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?