[root@k8s-master ~]# kubectl create namespace test1
namespace/test1 created
[root@k8s-master ~]# kubectl get ns
NAME STATUS AGE
default Active 13d
kube-node-lease Active 13d
kube-public Active 13d
kube-system Active 13d
kubernetes-dashboard Active 13d
test1 Active 5s
在test1里创建一个命名为web的nginx容器
[root@k8s-master ~]# kubectl create deployment web --image=nginx -n test1
deployment.apps/web created
[root@k8s-master ~]# kubectl get pods -n test1
NAME READY STATUS RESTARTS AGE
web-76b56fd968-g5z9c 1/1 Running 0 18s
暴露service并访问
[root@k8s-master ~]# kubectl expose deployment web --port=80 --target-port=80 --type=NodePort -n test1
service/web exposed
[root@k8s-master ~]# kubectl get svc -n test1
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web NodePort 10.107.118.153 <none>80:31824/TCP 20s
[root@k8s-master ~]# curl 192.168.11.11:31824<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>
html { color-scheme: light dark;}
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;}</style></head><body><h1>Welcome to nginx!</h1>......