获取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
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐