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端口