当前位置:网站首页>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)
边栏推荐
- Altair HyperWorks 2022 software installation package and installation tutorial
- MySQL常用图形管理工具 | 黑马程序员
- M91快速霍尔测量仪—在更短的时间内进行更好的测量
- How to realize the applet in its own app to realize continuous live broadcast
- 【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
- Memo - about C # generating barcode
- golang 错误处理
- 精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
- 如何在自有APP内实现小程序实现连麦直播
- bean的生命周期核心步骤总结
猜你喜欢

Three. JS learning - basic operation of camera (learn from)

实例讲解将Graph Explorer搬上JupyterLab

OpenAI|视频预训练 (VPT):基于观看未标记的在线视频的行动学习

Netease games, radical going to sea

用GSConv+Slim Neck改进Yolov5,将性能提升到极致!
![[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

Clean up system cache and free memory under Linux

Livedata postvalue will "lose" data

Example explanation: move graph explorer to jupyterlab

Leetcode-128 longest continuous sequence
随机推荐
Write an open source, convenient and fast database document query and generation tool with WPF
Summary of the core steps in the life cycle of beans
M91快速霍尔测量仪—在更短的时间内进行更好的测量
How to realize the applet in its own app to realize continuous live broadcast
Mipi interface, DVP interface and CSI interface of camera [easy to understand]
前4A高管搞代运营,拿下一个IPO
R language uses follow up of epidisplay package Plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses n.of The lines parameter specifies the num
Why do independent website sellers start to do social media marketing? The original customer conversion rate can be improved so much!
Popular science: what does it mean to enter the kernel state?
生鲜行业B2B电商平台解决方案,提高企业交易流程标准化和透明度
Lefse analysis
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
华为云专家详解GaussDB(for MySQL)新特性
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
R language epidisplay package ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval correspo
11、用户、组和权限(1)
【快应用】Win7系统使用华为IDE无法运行和调试项目
Navicat Premium 15 永久破解和2021版本最新IDEA破解(亲测有效)
Leetcode-141 circular linked list