机票
-
-
- 创建新namespace---test1
- 在test在1里创建一个命名web的nginx容器
- 暴露service并访问
- 删除service和web/namespace
-
创建新namespace—test1
[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
在test在1里创建一个命名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> ......
删除service和web/namespace
[root@k8s-master ~]# kubectl delete svc -n test1 web
service "web" deleted
[root@k8s-master ~]# kubectl delete deployment -n test1 web
deployment.apps "web" deleted
[root@k8s-master ~]# kubectl delete ns test1
namespace "test1" deleted