K8s实践指南
跳转到导航
跳转到搜索
深入service
集群外部访问pod or service
将容器应用的端口映射到物理机
1. hostPort
cat pod-hostport.yaml
apiVersion: v1
kind: Pod
metadata:
name: webapp
labels:
app: webapp
spec:
containers:
- name: webapp
image: tomcat
ports:
- containerPort: 8080
hostPort: 8081
kubectl create -f pod-hostport.yaml
#是没有反应的 哈哈
sudo netstat -nlpt | grep 8081
#此处masterip 为192.168.88.58
http://192.168.88.58:8081/
2.hostNetwork: true
cat pod-hostport.yaml
apiVersion: v1
kind: Pod
metadata:
name: webapp
labels:
app: webapp
spec:
hostNetwork: true
containers:
- name: webapp
image: tomcat
ports:
- containerPort: 8080
sudo netstat -nlpt | grep 808
tcp6 0 0 :::8080 :::* LISTEN 28100/java
http://192.168.88.58:8080/
service的端口映射到物理机
1. Nodeport
cat pod-hostport.yaml
apiVersion: v1
kind: Pod
metadata:
name: webapp
labels:
app: webapp
spec:
type: NodePort
- name: webapp
image: tomcat
ports:
- port: 8080
targetPort: 8080
NodePort: 8081
selector:
app: webapp
http://192.168.88.58:8081
2. 映射到云服务器提供商的loadbalancer 地址
DigitalOcean k8s
https://cloud.digitalocean.com/kubernetes/clusters?i=d097a0
可以测试在这上面买二到三台机器 比vultr便宜 不一定呢