将ClusterIP类型改为NodePort类型的一种方式
获取svc,查看nginx-deployment为ClusterIP类型[root@k8s-master01 ~]# kubectl get svcNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGEkubernetesClusterIP10.96.0.1...
·
获取svc,查看nginx-deployment为ClusterIP类型
[root@k8s-master01 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d20h
nginx-deployment ClusterIP 10.105.22.208 <none> 30000/TCP 2m17s
执行命令进行编辑
kubectl edit svc nginx-deployment
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2020-02-14T12:42:32Z"
labels:
run: nginx-deployment
name: nginx-deployment
namespace: default
resourceVersion: "312024"
selfLink: /api/v1/namespaces/default/services/nginx-deployment
uid: 77d51706-89eb-481c-918b-66b5fc8712fd
spec:
clusterIP: 10.105.22.208
ports:
- port: 30000
protocol: TCP
targetPort: 80
selector:
run: nginx-deployment
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
将 type: ClusterIP 修改为 type: NodePort,然后保存退出
然后获取svc,此时nginx-deployment是NodePort类型了
[root@k8s-master01 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d20h
nginx-deployment NodePort 10.105.22.208 <none> 30000:31868/TCP 8m49s
更多推荐
已为社区贡献19条内容
所有评论(0)