当前位置:网站首页>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
边栏推荐
- 解决方案:可以ping别人,但是别人不能ping我
- How to operate technology related we media well?
- Salesmartly has some tricks for Facebook chat!
- Privacy sandbox is finally coming
- Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
- bean的生命周期核心步骤总结
- R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
- Livedata postvalue will "lose" data
- Regular expression
- Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?
猜你喜欢
实现一个Prometheus exporter
Write an open source, convenient and fast database document query and generation tool with WPF
MySQL常用图形管理工具 | 黑马程序员
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
Stanford, salesforce|maskvit: masked vision pre training for video prediction
Lumiprobe non fluorescent alkyne EU (5-ethynyluridine)
如何在自有APP内实现小程序实现连麦直播
bean的生命周期核心步骤总结
C端梦难做,科大讯飞靠什么撑起10亿用户目标?
How to realize the applet in its own app to realize continuous live broadcast
随机推荐
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
1. "Create your own NFT collections and publish a Web3 application to show them." what is NFT
ES6数组去重的三个简单办法
Improve yolov5 with gsconv+slim neck to maximize performance!
摄像头的MIPI接口、DVP接口和CSI接口[通俗易懂]
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
Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?
VBA simple macro programming of Excel
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
Lumiprobe lumizol RNA extraction reagent solution
AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖
【快应用】Win7系统使用华为IDE无法运行和调试项目
助力数字经济发展,夯实数字人才底座—数字人才大赛在昆成功举办
PriorityQueue的用法和底层实现原理
R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, and calculate the summary statistics of each subset
Implement a Prometheus exporter
Write it down once Net travel management background CPU Explosion Analysis
Summary of the core steps in the life cycle of beans
How to operate technology related we media well?
生鲜行业B2B电商平台解决方案,提高企业交易流程标准化和透明度