7B. 我用K8S部署的第一个应用(LoadBalancer可以外网访问)
跟7A差不多,只是NodePort换成了LoadBalancer。
以下4种方式都可以访问应用:
1.浏览器输入106.52.14.84:8000
2.curl 106.52.14.84:8000
3.curl 10.0.8.10:8000
4.curl 10.0.8.10:32247
chengjisihan-svc.yml
apiVersion: v1
kind: Service
metadata:
name: chengjisihan-svc
labels:
app: chengji-Lab1
spec:
#type: NodePort
type: LoadBalancer
ports:
- port: 8000
targetPort: 8000
protocol: TCP
selector:
app: chengji-Lab1
chengjisihan-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: chengji-pod
labels:
app: chengji-Lab1
spec:
containers:
- name: web
image: seasonzhang/chengjisihanv3:1.0
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 8000
name: chengji-pod
protocol: TCP