このページの翻訳:
- 日本語 (ja)
- English (en)
最近の更新
Tag Cloud
このページへのアクセス
今日: 8 / 昨日: 0
総計: 633
- Dokuwiki.fl8.jp(463)
- 13 CentOS6メール設定(23)
- FreeBSD カーネル再構築(20)
- 05 rsync(20)
最近の更新
このページへのアクセス
今日: 8 / 昨日: 0
総計: 633
3つのnginxを立ててみる
nginx.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 3 selector: matchLabels: app: nginx-app template: metadata: labels: app: nginx-app spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
kubectl create -f nginx.yaml
# kubectl get deployments.apps -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR nginx 3/3 3 3 24s nginx nginx:latest app=nginx-app # kubectl get pod NAME READY STATUS RESTARTS AGE nginx-59bc74c488-669ng 1/1 Running 0 9m34s nginx-59bc74c488-csj8x 1/1 Running 0 9m34s nginx-59bc74c488-dc2zq 1/1 Running 0 9m34s
# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-6c57499ddb-pjql2 1/1 Running 1 (17m ago) 55m 10.224.1.15 worker01 <none> <none> nginx-6c57499ddb-tfghq 1/1 Running 1 (17m ago) 55m 10.224.1.14 worker01 <none> <none> nginx-6c57499ddb-zg88c 1/1 Running 1 (17m ago) 55m 10.224.1.17 worker01 <none> <none>
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
root@worker01:~# curl 10.224.1.15 pod1 root@worker01:~# curl 10.224.1.14 pod2 root@worker01:~# curl 10.224.1.17 pod3
cluster ipの8080にアクセスが来ると、nginx-appへ渡す
clusterIp.yaml
apiVersion: v1 kind: Service metadata: name: cluster-ip spec: type: ClusterIP ports: - name: cluster-port port: 8080 targetPort: 80 selector: app: nginx-app
# 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
cluster ipの8080にアクセスすると、podどれかにアクセスする
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
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
# 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
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