k8s-命令創建service


查看命令幫助

[root@master kubernetes]# kubectl create service -h
Create a service using specified subcommand.

Aliases:
service, svc

Available Commands:
  clusterip    Create a ClusterIP service.
  externalname Create an ExternalName service.
  loadbalancer 創建一個 LoadBalancer service.
  nodeport     創建一個 NodePort service.

Usage:
  kubectl create service [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all
commands).

 

[root@master kubernetes]# kubectl create service clusterip ngx-dep --tcp=80:80
service/ngx-dep created

 

 

[root@master kubernetes]# kubectl get svc/ngx-dep -o wide
NAME      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE   SELECTOR
ngx-dep   ClusterIP   10.96.79.198   <none>        80/TCP    79s   app=ngx-dep
[root@master kubernetes]# kubectl describe svc/ngx-dep
Name:              ngx-dep
Namespace:         default
Labels:            app=ngx-dep
Annotations:       <none>
Selector:          app=ngx-dep
Type:              ClusterIP
IP:                10.96.79.198
Port:              80-80  80/TCP
TargetPort:        80/TCP
Endpoints:         10.100.166.129:80
Session Affinity:  None
Events:            <none>
[root@master kubernetes]#

 

 

[root@master kubernetes]# kubectl create svc nodeport ngx-dep --tcp=80:80

 

[root@master kubernetes]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12h
nginx NodePort 10.96.218.42 <none> 80:32548/TCP 11h
ngx-dep NodePort 10.96.106.83 <none> 80:30606/TCP 12s

 

使用外面機器 訪問30606端口

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM