ユーザ用ツール

サイト用ツール


06_virtualization:05_container:13_kubernetes_create_nginx

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

06_virtualization:05_container:13_kubernetes_create_nginx [2022/04/15 09:38] – 作成 matsui06_virtualization:05_container:13_kubernetes_create_nginx [2022/04/15 10:39] (現在) matsui
行 44: 行 44:
 </code> </code>
  
-===== 2.確認用の Ubuntu用意 =====+===== 2.確認用にNginx表示変更 =====
  
-<code|ubuntu.yaml>+==== Podを確認 ==== 
 + 
 +<code> 
 +# kubectl get pod -o wide 
 +NAME                     READY   STATUS    RESTARTS      AGE   IP            NODE       NOMINATED NODE   READINESS GATES 
 +nginx-6c57499ddb-pjql2   1/    Running   1 (17m ago)   55m   10.224.1.15   worker01   <none>           <none> 
 +nginx-6c57499ddb-tfghq   1/    Running   1 (17m ago)   55m   10.224.1.14   worker01   <none>           <none> 
 +nginx-6c57499ddb-zg88c   1/    Running   1 (17m ago)   55m   10.224.1.17   worker01   <none>           <none> 
 +</code> 
 + 
 +==== Podそれぞれ表示を変える ==== 
 + 
 +<code> 
 +kubectl exec -it  nginx-6c57499ddb-pjql2 -- bash 
 +echo pod1 | tee /usr/share/nginx/html/index.html 
 +exit 
 + 
 +kubectl exec -it  nginx-6c57499ddb-tfghq -- bash 
 +echo pod2 | tee /usr/share/nginx/html/index.html 
 +exit 
 + 
 +kubectl exec -it  nginx-6c57499ddb-zg88c -- bash 
 +echo pod3 | tee /usr/share/nginx/html/index.html 
 +exit 
 +</code> 
 + 
 +===== 3.workerノードで確認 ===== 
 + 
 +<code> 
 +root@worker01:~# curl 10.224.1.15 
 +pod1 
 +root@worker01:~# curl 10.224.1.14 
 +pod2 
 +root@worker01:~# curl 10.224.1.17 
 +pod3 
 +</code> 
 + 
 + 
 +===== 4.cluster IP 作成 ===== 
 + 
 +cluster ipの8080にアクセスが来ると、nginx-appへ渡す 
 + 
 +<code|clusterIp.yaml>
 apiVersion: v1 apiVersion: v1
-kind: Pod+kind: Service
 metadata: metadata:
-  name: ubuntu+  name: cluster-ip
 spec: spec:
-  containers+  type: ClusterIP 
-    - name: ubuntu +  ports
-      imageubuntu +    - name: cluster-port 
-      command+      port8080 
-        - sleep +      targetPort80 
-        infinity+  selector: 
 +    app: nginx-app
 </code> </code>
  
 <code> <code>
-# kubectl create -f ubuntu.yaml+# kubectl create -f clusterIp.yaml 
 +# kubectl get svc 
 +NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE 
 +cluster-ip   ClusterIP   10.105.186.186   <none>        8080/TCP   10m 
 +kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP    85m 
 +</code>
  
-kubectl get pods ubuntu  +===== 5.再度workerノードで確認 ===== 
-NAME     READY   STATUS    RESTARTS   AGE + 
-ubuntu   1/    Running            6m13s+cluster ipの8080にアクセスすると、podどれかにアクセスする 
 + 
 +<code> 
 +root@worker01:~curl 10.105.186.186:8080 
 +pod3 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod2 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod1 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod2 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod1 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod2 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod1 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod2 
 +root@worker01:~# curl 10.105.186.186:8080 
 +pod1
 </code> </code>
  
 +===== 6. ExternalIP用意 =====
 +
 +<code|externalIp.yaml>
 +apiVersion: v1
 +kind: Service
 +metadata:
 +  name: external-ip
 +spec:
 +  type: ClusterIP
 +  externalIPs:
 +    - 172.16.0.159
 +  ports:
 +    - name: cluster-port
 +      port: 8080
 +      targetPort: 80
 +  selector:
 +    app: nginx-app
 +</code>
 +
 +<code>
 +# kubectl create -f externalIp.yaml
 +# kubectl get svc external-ip 
 +NAME          TYPE        CLUSTER-IP       EXTERNAL-IP    PORT(S)    AGE
 +external-ip   ClusterIP   10.101.128.182   172.16.0.159   8080/TCP   83s
 +</code>
 +
 +===== 7.次は外部からアクセス可能 =====
 +
 +<code>
 +root@jump:~# curl 172.16.0.159:8080
 +pod3
 +root@jump:~# curl 172.16.0.159:8080
 +pod1
 +root@jump:~# curl 172.16.0.159:8080
 +pod1
 +root@jump:~# curl 172.16.0.159:8080
 +pod3
 +root@jump:~# curl 172.16.0.159:8080
 +pod2
 +</code>
  
 {{tag>Kubernetes}} {{tag>Kubernetes}}
06_virtualization/05_container/13_kubernetes_create_nginx.1650015524.txt.gz · 最終更新: 2022/04/15 09:38 by matsui