Deployment3
http://域名 访问ipquery
目标: 通过apply创建了 ipquery 对应的deployment,它具有4个副本。通过get pods 可以查询4个副本的状态。 并且通过ingress实现http域名访问ipquery
(1) 前置条件
DNS域名服务指向其中一台节点服务器 queryip.michaelapp.com 指向节点服务器
并且安装了Nginx Ingress Controller
(2) 创建deployment声明文件
ipquery-ingress-http.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ipquery-v1
labels:
app: ipquery-v1
spec:
replicas: 4
selector:
matchLabels:
app: ipquery-v1
template:
metadata:
labels:
app: ipquery-v1
spec:
containers:
- name: ipquery-k8s
image: lorahz/ipquery:1.10
---
apiVersion: v1
kind: Service
metadata:
name: ipquery-v1
labels:
app: ipquery-v1
spec:
selector:
app: ipquery-v1
ports:
- name: ipquery-v1
protocol: TCP
port: 9999
targetPort: 8888
type: LoadBalancer
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ipquery-v1
spec:
rules:
- host: queryip.michaelapp.com
http:
paths:
- path: /
backend:
serviceName: ipquery-v1
servicePort: 9999
(3) 使用kubctl apply 或者 kubctl create创建deployment
//创建deployment
[root@t1 ipquery]# kubectl apply -f ipquery-ingress-http.yaml
deployment.apps/ipquery-v1 created
service/ipquery-v1 created
ingress.networking.k8s.io/ipquery-v1 created
//查询deployment对应的pods列表
[root@t1 ipquery]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ipquery-v1 LoadBalancer 10.96.68.39 <pending> 9999:30293/TCP 12s
//查询deployment
[root@t1 ipquery]# kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
ipquery-v1 4/4 4 4 3m18s
nginx-deployment 1/1 1 1 20m
(4) 如何访问Pod
浏览器或者curl http://queryip.michaelapp.com/
[root@t1 ipquery]# curl http://queryip.michaelapp.com/
{"result":"Welcome Michal.Pan's IPQuery Server!","status":200,"uuid":"1715dc88-bf2a-4fb9-9f6c-85f49906c2d4"}
[root@t1 ipquery]# curl http://queryip.michaelapp.com/
{"result":"Welcome Michal.Pan's IPQuery Server!","status":200,"uuid":"cf68923a-08e9-44af-b861-8f8728244406"}
[root@t1 ipquery]# curl http://queryip.michaelapp.com/
{"result":"Welcome Michal.Pan's IPQuery Server!","status":200,"uuid":"1eecfa11-d2da-42b0-bc5f-cc0cb88e27cd"}
[root@t1 ipquery]# curl http://queryip.michaelapp.com/
{"result":"Welcome Michal.Pan's IPQuery Server!","status":200,"uuid":"cf68923a-08e9-44af-b861-8f8728244406"}
[root@t1 ipquery]# curl http://queryip.michaelapp.com/
{"result":"Welcome Michal.Pan's IPQuery Server!","status":200,"uuid":"cf68923a-08e9-44af-b861-8f8728244406"}
(5)参考链接
kubernetes-ingress-controller(nginx)