k8s 创建新namespace / deployment并暴露service

创建新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

在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>
......

删除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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丶伯爵式

大爷~您看着给~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值