K8S k8s(5)__网络模式 发表于 2022-09-02 浏览量 479 没有评论 # Docker的网络模式 默认桥接Docker0,外界无法访问 端口映射 主机网络 # K8S端口映射配置 ``` cat create.yml apiVersion: v1 kind: ReplicationController metadata: name: nginx spec: replicas: 1 template: metadata: name: nginx labels: app: nginx spec: containers: - name: mynginx imagePullPolicy: Always image: 192.168.237.50:5000/shijiange:nginx ports: - containerPort: 80 hostPort: 90 ``` 启动端口映射说明 需要注意端口冲突。同一个Pod无法启动多个相同容器,因为端口冲突 kubectl --server=192.168.237.50:8080 scale rc nginx --replicas=x # K8S主机模式启动容器配置 ``` cat create.yml apiVersion: v1 kind: ReplicationController metadata: name: nginx spec: replicas: 1 template: metadata: name: nginx labels: app: nginx spec: containers: - name: mynginx imagePullPolicy: Always image: 192.168.237.50:5000/shijiange:nginx hostNetwork: true ``` 主机模式启动容器说明 需要注意端口冲突。同一个Pod无法启动多个相同容器,因为端口冲突 kubectl --server=192.168.237.50:8080 scale rc nginx --replicas=x