Kubernetes----Pod配置容器端口
一、配置Pod的端口配置
1.1 编写yaml文件
编写 pod_ports.yaml文件,内容如下,设置port的name和containerPort,如下
apiVersion: v1kind: Namespacemetadata: name: dev---apiVersion: v1kind: Podmetadata: name: pod-ports namespace: dev labels: user: redrose2100spec: containers: - name: nginx image: nginx:1.17.1 ports: - containerPort: 80 name: nginx-port protocol:
1.2 创建资源
使用如下命令创建资源
[root@master pod]# kubectl apply -f pod_ports.yamlnamespace/dev createdpod/pod-ports created[root@master pod]#
1.3 查看Pod的IP和端口等信息
使用如下命令可以查看到ip和端口
[root@master pod]# kubectl get pod -n dev -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod-ports 1/1 Running 0 3m 10.244.2.36 node2 [root@master pod]# kubectl describe pod pod-ports -n devName: pod-portsNamespace: devPriority: 0Node: node2/192.168.16.42Start Time: Tue, 22 Mar 2022 00:55:03 +0800Labels: user=redrose2100Annotations: Status: RunningIP: 10.244.2.36IPs: IP: 10.244.2.36Containers: nginx: Container ID: docker://b3514575830f43fdedf27a2ed784f52c41183b22a7cd2050fad361ce0802ef41 Image: nginx:1.17.1 Image ID: docker-pullable://nginx@sha256:b4b9b3eee194703fc2fa8afa5b7510c77ae70cfba567af1376a573a967c03dbb Port: 80/TCP Host Port: 0/TCP State: Running Started: Tue, 22 Mar 2022 00:55:04 +0800 Ready: True Restart Count: 0 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9c8z2 (ro)Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled TrueVolumes: kube-api-access-9c8z2: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: DownwardAPI: trueQoS Class: BestEffortNode-Selectors: Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300sEvents: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 3m8s default-scheduler Successfully assigned dev/pod-ports to node2 Normal Pulled 3m7s kubelet Container image "nginx:1.17.1" already present on machine Normal Created 3m7s kubelet Created container nginx Normal Started 3m7s kubelet Started container nginx[root@master pod]#
1.4 使用IP和端口验证
在集群环境中使用ip+port访问nginx,如下,即能正确访问nginx
[root@master pod]# curl 10.244.2.36:80
Welcome to nginx!
Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer to
[root@master pod]#
1.5 删除资源
使用如下命令删除资源
[root@master pod]# kubectl delete -f pod_ports.yamlnamespace "dev" deletedpod "pod-ports" deleted[root@master pod]#
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~