当前位置:网站首页>Getting started with kubernetes command (namespaces, pods)
Getting started with kubernetes command (namespaces, pods)
2022-07-01 19:11:00 【dream21st】
List of articles
1 nameSpace Introduce
namespace The Chinese name of is namespace . You can think namespaces It's you kubernetes Virtualization in clusters . In a Kubernetes A cluster can have multiple namespaces , They are logically isolated from each other . Can provide you with organization , Help with safety and even performance !
namespace An abstract collection of resources and objects , For example, it can be used to divide the objects in the system into different project groups or user groups . common pods, services, replication controllers and deployments All belong to a certain namespace Of ( The default is default), and node, persistentVolumes And so on does not belong to any namespace.
Most of the Kubernetes By default, there will be a cluster called default Of namespace. actually , Should be 4 individual :
1,default: Your resources are created by default in default Namespace .
2,kube-system:kubernetes System components use .
3,kube-node-lease: kubernetes Cluster node lease status ,v1.13 Join in
4,kube-public: Use of public resources . But it's not commonly used now .
This default (default) Of namespace It's nothing special , But you can't delete it . This is good for just starting to use kubernetes And some small product systems . However, it is not recommended to apply it to large-scale production systems . because , In this complex system , Teams can easily rewrite or interrupt other services unexpectedly or unconsciously service. contrary , Please create multiple namespaces to put your service( service ) Split into more manageable chunks .
effect : In the case of multi tenancy , Realize resource isolation : It belongs to logical isolation ; It belongs to the management boundary ; Not belonging to the network boundary ; For each namespace Make resource quotas .
1.1 View namespace
# Check the namespace spelling
[[email protected] ~]# kubectl get namespaces
# View namespace abbreviations
[[email protected] ~]# kubectl get ns
Check the... Under the namespace pod:
[[email protected] ~]# kubectl get pod --all-namespaces
[[email protected] ~]# kubectl get pod -A
The default namespace is as follows :
default User created pod Default in this namespace
kube-public All users can access , Include unauthenticated users
kube-node-lease kubernetes Cluster node lease status ,v1.13 Join in
kube-system kubernetes Clusters are using
1.2 Create a namespace
[[email protected] ~]# kubectl create namespace dream21th-one
namespace/dream21th-one created
[[email protected] ~]# kubectl create ns dream21th-two
namespace/dream21th-two created
[[email protected] ~]# kubectl get ns
NAME STATUS AGE
default Active 118d
dream21th-one Active 49s
dream21th-two Active 30s
kube-node-lease Active 118d
kube-public Active 118d
kube-system Active 118d
1.3 Delete namespace
[[email protected] ~]# kubectl delete namespace dream21th-one
namespace "dream21th-one" deleted
[[email protected] ~]# kubectl delete ns dream21th-two
namespace "dream21th-two" deleted
[[email protected] ~]# kubectl get ns
NAME STATUS AGE
default Active 118d
kube-node-lease Active 118d
kube-public Active 118d
kube-system Active 118d
2 pod brief introduction
Pod yes kubernetes The smallest unit that the cluster can schedule .Pod It's the packaging of the container . stay Kubernetes In the cluster ,Pod It is the foundation of all business types , It's also K8S The smallest unit level of management , It is a combination of one or more containers . These containers share storage 、 Networks and namespaces , And how to run the specifications . stay Pod in , All containers are the same
I. arrangement and scheduling , And run in a shared context . For specific applications ,Pod Is their logical host ,Pod Contains multiple application containers related to business .
The Internet : every last Pod Will be assigned a unique Ip Address , stay Pod Each container in the shared network namespace , Include Ip Address and network port . In the same Pod The container in can be connected with localhost Communicate with each other . When Pod Containers in need of Pod When communicating with entities outside , You need to share network resources through ports, etc .
Storage :Pod A collection of shared storage volumes that can be specified , stay Pod All containers in the can access shared storage volumes , Allow these containers to share data . Storage volumes are also allowed in a Pod Persistent data , In case the container needs to be restarted .
K8s You don't usually create Pod. Instead, the controller and template configuration are used to manage and schedule the Pod Containers in may terminate and exit due to exceptions and other reasons ,kubernetes A restart strategy is provided to restart the container . The restart policy is for the same Pod All containers of work , The restart of the container is controlled by Node Upper kubelet perform .Pod Three restart strategies are supported , Pass... In the configuration file restartPolicy Field to set the restart policy ( Be careful , Restart here refers to Pod Host of Node Local restart on , Instead of dispatching to other Node On ):
1,Always: Just exit and restart ;
2,OnFailure: Only if you fail to quit (exit code It's not equal to 0) when , Will restart ;
3,Never: Just quit , No restart .
Kubernetes adopt cgroups Limiting the container CPU And computing resources like memory , Include requests( request , The scheduler ensures that resources are sufficient Node On ) and limits( ceiling ) etc. .
2.1 see pod
# see default Under the namespace pods
[[email protected] ~]# kubectl get pods
No resources found in default namespace.
# see kube-system Under the namespace pods
[[email protected] ~]# kubectl get pods -n kube-system
# View all namespaces pods
[[email protected] ~]# kubectl get pod --all-namespaces
[[email protected] ~]# kubectl get pod -A
2.2 establish pod
Download mirroring :
[[email protected] ~]# docker pull tomcat:9.0.20-jre8-alpine
function pod:
# stay default Namespace pod Replica deployment
[[email protected] ~]# kubectl run tomcat9-test --image=tomcat:9.0.20-jre8-alpine --port=8080
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/tomcat9-test created
[[email protected] ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
tomcat9-test-569b5bf455-9bvzs 1/1 Running 0 14s
[[email protected] ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
tomcat9-test-569b5bf455-9bvzs 1/1 Running 0 22s 10.244.2.3 k8s-work2 <none> <none>
# Use pod Of IP Access to the container
[[email protected] ~]# curl 10.244.2.3:8080
2.3 Capacity expansion
# Expand to 3 individual
[[email protected] ~]# kubectl scale --replicas=3 deployment/tomcat9-test
deployment.apps/tomcat9-test scaled
# see pod
[[email protected] ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
tomcat9-test-569b5bf455-9bvzs 1/1 Running 0 4m17s
tomcat9-test-569b5bf455-s826c 0/1 ContainerCreating 0 5s
tomcat9-test-569b5bf455-zx4zk 0/1 ContainerCreating 0 5s
[[email protected] ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
tomcat9-test-569b5bf455-9bvzs 1/1 Running 0 4m22s 10.244.2.3 k8s-work2 <none> <none>
tomcat9-test-569b5bf455-s826c 1/1 Running 0 10s 10.244.1.5 k8s-work1 <none> <none>
tomcat9-test-569b5bf455-zx4zk 1/1 Running 0 10s 10.244.1.4 k8s-work1 <none> <none>
# View deployment
[[email protected] ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
tomcat9-test 3/3 3 3 4m40s
[[email protected] ~]# kubectl get deployment -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
tomcat9-test 3/3 3 3 4m52s tomcat9-test tomcat:9.0.20-jre8-alpine run=tomcat9-test
[[email protected] ~]# curl 10.244.2.3:8080
2.4 Create services
[[email protected] ~]# kubectl expose deployment tomcat9-test --name=tomcat9-svc --port=8888 --target-port=8080 --protocol=TCP --type=NodePort
service/tomcat9-svc exposed
[[email protected] ~]# kubtck get pod
-bash: kubtck: Command not found
[[email protected] ~]# kubtck get pods
-bash: kubtck: Command not found
[[email protected] ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
tomcat9-test-569b5bf455-9bvzs 1/1 Running 0 16m
tomcat9-test-569b5bf455-s826c 1/1 Running 0 12m
tomcat9-test-569b5bf455-zx4zk 1/1 Running 0 12m
[[email protected] ~]# kubtck get svc
-bash: kubtck: Command not found
[[email protected] ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 118d
tomcat9-svc NodePort 10.96.33.14 <none> 8888:30286/TCP 40s
[[email protected] ~]# curl 10.96.33.14:8888
Visit... On the browser http://192.168.43.103:30286/ It can also be accessed normally .
3 Commonly used instructions
3.1 get
kubectl get: List one or more resources .
# View the cluster status information
[[email protected] ~]# kubectl cluster-info
[[email protected] ~]# kubectl get cs
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {
"health":"true"}
# View the cluster node information
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 118d v1.17.5
k8s-work1 Ready <none> 118d v1.17.5
k8s-work2 Ready <none> 118d v1.17.5
# View the cluster namespace
[[email protected] ~]# kubectl get ns
# View the services of the specified namespace
[[email protected] ~]# kubectl get svc -n kube-system
# List all... In plain text output format pod.
[[email protected] ~]# kubectl get pods
# List all... In plain text output format pod, And include additional information ( Such as node roll call ).
[[email protected] ~]# kubectl get pods -o wide
# Lists all replica controllers and services in plain text output format .
[[email protected] ~]# kubectl get rc,services
# List in node server01 All of the pod
[[email protected] ~]# kubectl get pods --field-selector=spec.nodeName=k9s-master
3.2 describe
kubectl describe - Displays the detailed status of one or more resources , Uninitialized resources are included by default .
[[email protected] ~]# kubectl describe nodes k8s-master
[[email protected] ~]# kubectl describe pods tomcat9-test-569b5bf455-9bvzs
3.3 delete
kubectl delete` - From file 、stdin Or specify a label selector 、 name 、 Delete a resource from the resource selector or resource .
# Use pod.yaml Delete the type and name specified in the file pod.
kubectl delete -f pod.yaml
# Delete tag name = <label-name> All of the pod And the service .
kubectl delete pods,services -l name=<label-name>
# Delete all with tag names = <label-name> Of pod And the service , Including those uninitialized .
kubectl delete pods,services -l name=<label-name> --include-uninitialized
# Delete all pod, Include uninitialized pod.
kubectl delete pods --all
3.4 Into the container
kubectl exec - Yes pod The container in executes the command . And docker Of exec The orders are very similar .
# from pod <pod-name> Get run 'date' Output . By default , The output comes from the first container .
kubectl exec <pod-name> date
# Operation output 'date' Get the... In the container <container-name> in pod <pod-name> Output .
kubectl exec <pod-name> -c <container-name> date
# Get an interactive TTY And run /bin/bash <pod-name >. By default , The output comes from the first container .
kubectl exec -ti <pod-name> /bin/bash
3.5 logs
kubectl logs - Print Pod Log of the container in .
# from pod Return to log snapshot .
kubectl logs <pod-name>
# from pod <pod-name> Start streaming logs . This is similar to 'tail -f' Linux command .
kubectl logs -f <pod-name>
3.6 Format output
[[email protected] ~]# kubectl get pod tomcat9-test-569b5bf455-9bvzs -o yaml
3.7 Mandatory deletion pod
Force the deletion of a pod
--force --grace-period=0
4 Resource abbreviation
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-X0Kd3RqD-1656583866075)(D:\developsoftware\mayun\note\study-note\docker\images\image-20220630175627753.png)]](/img/92/c835709ed5b0986d4386f2ae30c24a.png)
边栏推荐
- js找出数字在数组中下一个相邻的元素
- bean的生命周期核心步骤总结
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- 2020,最新手机号码手机验证正则表达式,持续更新
- Gameframework eating guide
- GameFramework食用指南
- Stanford, salesforce|maskvit: masked vision pre training for video prediction
- Cache problems after app release
- How to realize the applet in its own app to realize continuous live broadcast
- Netease games, radical going to sea
猜你喜欢

Write an open source, convenient and fast database document query and generation tool with WPF

C端梦难做,科大讯飞靠什么撑起10亿用户目标?

Leetcode-21 combines two ordered linked lists
![[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched](/img/5c/b0030fd5fbc07eb94013f2699c2a04.png)
[quick application] there are many words in the text component. How to solve the problem that the div style next to it will be stretched

June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries

Solution: you can ping others, but others can't ping me

Viewing the whole ecology of Tiktok from a macro perspective

水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益

Lumiprobe 细胞成像研究丨PKH26细胞膜标记试剂盒

Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书
随机推荐
golang 错误处理
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
How to operate technology related we media well?
Games202 operation 0 - environment building process & solving problems encountered
Stanford, salesforce|maskvit: masked vision pre training for video prediction
Go language self-study series | go language data type
Qt中的QFile读写文件操作
AI training speed breaks Moore's law; Song shuran's team won the RSS 2022 Best Paper Award
Mipi interface, DVP interface and CSI interface of camera [easy to understand]
数商云:从规划到落地,五矿集团如何快速构建数字化发展新格局?
Technology implementation and Architecture Practice
R language ggplot2 visualization: gganimate creates a dynamic histogram animation (GIF), and displays the histogram and enter step by step along a given dimension in the animation_ Growth function and
Privacy sandbox is finally coming
GameFramework食用指南
3. "Create your own NFT collections and publish a Web3 application to show them" cast NFT locally
Huawei game failed to initialize init with error code 907135000
一次SQL优化,数据库查询速度提升 60 倍
M91快速霍尔测量仪—在更短的时间内进行更好的测量
OpenAI|视频预训练 (VPT):基于观看未标记的在线视频的行动学习
Prices of Apple products rose across the board in Japan, with iphone13 up 19%