Flutter开发App的未来及其在各行业的应用潜力分析
724
2022-12-01
【K8S运维知识汇总】第3天1:kubectl详解——陈述式资源管理方法(deployment资源、service资源)
查看名称空间:
[root@hdss7-21 ~]# kubectl get namespace # 等同于kubectl get nsNAME STATUS AGEdefault Active 3d22hkube-node-lease Active 3d22hkube-public Active 3d22hkube-system Active 3d22h
查看defalut名称空间下的所有资源:
[root@hdss7-21 ~]# kubectl get all -n default # 等同于kubectl get allNAME READY STATUS RESTARTS AGEpod/nginx-ds-pqszs 1/1 Running 0 2d12hpod/nginx-ds-vnlx9 1/1 Running 0 2d12hNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 192.168.0.1
创建名称空间:
[root@hdss7-21 ~]# kubectl create namespace appnamespace/app created[root@hdss7-21 ~]# kubectl get nsNAME STATUS AGEapp Active 45sdefault Active 3d23hkube-node-lease Active 3d23hkube-public Active 3d23hkube-system Active 3d23h
删除名称空间:
[root@hdss7-21 ~]# kubectl delete namespace appnamespace "app" deleted[root@hdss7-21 ~]# kubectl get nsNAME STATUS AGEdefault Active 3d23hkube-node-lease Active 3d23hkube-public Active 3d23hkube-system Active 3d23h
创建deployment资源:
# 在名称为kube-public的名称空间创建名称为nginx-db资源进行pod控制[root@hdss7-21 ~]# kubectl create deployment nginx-dp --image=harbor.od.com/public/nginx:v1.7.9 -n kube-publicdeployment.apps/nginx-db created[root@hdss7-21 ~]# kubectl get deploy -n kube-publicNAME READY UP-TO-DATE AVAILABLE AGEnginx-db 0/1 1 0 2m28s[root@hdss7-21 ~]# kubectl get pods -n kube-publicNAME READY STATUS RESTARTS AGEnginx-db-7b4dd9978d-8wzdl 0/1 Pending 0
查看 kube-public名称空间下的Pod
[root@hdss7-21 ~]# kubectl get pods -n kube-public -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx-db-7b4dd9978d-8wzdl 0/1 Pending 0 8m15s
查看详细信息:
[root@hdss7-21 ~]# kubectl describe deployment nginx-db -n kube-publicName: nginx-dbNamespace: kube-publicCreationTimestamp: Wed, 01 Jul 2020 10:58:43 +0800Labels: app=nginx-dbAnnotations: deployment.kubernetes.io/revision: 1Selector: app=nginx-dbReplicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailableStrategyType: RollingUpdate # 发布策略:滚动升级MinReadySeconds: 0RollingUpdateStrategy: 25% max unavailable, 25% max surgePod Template: Labels: app=nginx-db Containers: nginx: Image: harbor.od.com/public/nginx:v1.7.9 Port:
进入pod资源
[root@hdss7-21 ~]# kubectl get pods -n kube-publicNAME READY STATUS RESTARTS AGEpod/nginx-dp-5dfc689474-fc6z9 1/1 Running 0 4s# kubectl exec可以跨主机进入不同的pod[root@hdss7-21 ~]# kubectl exec -it nginx-dp-5dfc689474-fc6z9 /bin/bash root@nginx-ds-pqszs:/# ip addr1: lo:
删除pod资源:删除后,pod控制器会立即重启一个新的pod资源,是重启Pod的重要方法
[root@hdss7-21 ~]# kubectl delete pod nginx-db-7b4dd9978d-8wzdl -n kube-public pod "nginx-db-7b4dd9978d-8wzdl" deleted# 强制删除[root@hdss7-21 ~]# kubectl delete pod nginx-db-7b4dd9978d-8wzdl -n kube-public --force --grace-period=0
删除deployment资源
[root@hdss7-21 ~]# kubectl delete deployment nginx-db -n kube-publicdeployment.extensions "nginx-db" deleted[root@hdss7-21 ~]# kubectl get deployment -n kube-publicNo resources found.[root@hdss7-21 ~]# kubectl get pods -n kube-publicNo resources found.[root@hdss7-21 ~]#
创建service资源
# 暴露80端口[root@hdss7-21 ~]# kubectl expose deployment nginx-dp --port=80 -n kube-publicservice/nginx-dp exposed[root@hdss7-21 ~]# kubectl get all -n kube-publicNAME READY STATUS RESTARTS AGEpod/nginx-dp-5dfc689474-4dfsq 1/1 Running 0 44m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/nginx-dp ClusterIP 192.168.103.156
查看端口是否可访问
# 当无法curl时,检查宿主机的内核中是否开启了ipv4转发功能[root@hdss7-21 ~]# cat /proc/sys/net/ipv4/ip_forward0[root@hdss7-21 ~]# echo "1" >!$echo "1" >/proc/sys/net/ipv4/ip_forward[root@hdss7-21 ~]# cat /proc/sys/net/ipv4/ip_forward1[root@hdss7-21 ~]# curl 192.168.103.156
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer to
# 访问成功# 查看lvs服务信息[root@hdss7-21 ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.0.1:443 nq -> 10.4.7.21:6443 Masq 1 0 0 -> 10.4.7.22:6443 Masq 1 0 0 TCP 192.168.103.156:80 nq -> 172.7.22.2:80 Masq 1 0 0对deployment资源扩容:默认创建时只有一个pod资源
[root@hdss7-21 ~]# kubectl scale deployment nginx-dp --replicas=2 -n kube-publicdeployment.extensions/nginx-dp scaled# 查看扩容后的信息[root@hdss7-21 ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.0.1:443 nq -> 10.4.7.21:6443 Masq 1 0 0 -> 10.4.7.22:6443 Masq 1 0 0 TCP 192.168.103.156:80 nq -> 172.7.22.2:80 Masq 1 0 0 -> 172.7.22.3:80 Masq 1 0 0
查看svc详细信息
[root@hdss7-21 ~]# kubectl describe svc nginx-dp -n kube-publicName: nginx-dp # service资源名称Namespace: kube-publicLabels: app=nginx-dpAnnotations:
总结
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~