当前位置:网站首页>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)
边栏推荐
- Technology implementation and Architecture Practice
- Qfile read / write file operation in QT
- Docker deploy mysql8.0
- Taiaisu M source code construction, peak store app premium consignment source code sharing
- Reading notes series "modern methods of C language programming" -- Chapter 2
- Yyds dry inventory ravendb start client API (III)
- Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
- Stanford, salesforce|maskvit: masked vision pre training for video prediction
- 苹果产品在日本全面涨价,iPhone13涨19%
- AppGallery Connect场景化开发实战—图片存储分享
猜你喜欢

一次SQL优化,数据库查询速度提升 60 倍

Memo - about C # generating barcode for goods

MySQL常用图形管理工具 | 黑马程序员

如何使用物联网低代码平台进行个人设置?

Implement a Prometheus exporter

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

ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享

Navicat Premium 15 永久破解和2021版本最新IDEA破解(亲测有效)

Privacy sandbox is finally coming

Halcon image calibration enables subsequent image processing to become the same as the template image
随机推荐
摄像头的MIPI接口、DVP接口和CSI接口[通俗易懂]
如何使用物联网低代码平台进行个人设置?
Go语言自学系列 | go语言数据类型
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Taiaisu M source code construction, peak store app premium consignment source code sharing
C-end dream is difficult to achieve. What does iFLYTEK rely on to support the goal of 1billion users?
Docker deploy mysql8.0
C端梦难做,科大讯飞靠什么撑起10亿用户目标?
The R language cartools package divides the data, the scale function scales the data, the KNN function of the class package constructs the k-nearest neighbor classifier, and the table function calcula
Implement a Prometheus exporter
11、用户、组和权限(1)
Graduation summary
Viewing technological changes through Huawei Corps (VI): smart highway
实例讲解将Graph Explorer搬上JupyterLab
Shell array
苹果产品在日本全面涨价,iPhone13涨19%
Love business in Little Red Book
How to realize the bottom layer of read-write lock in go question bank 16
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
用WPF写一款开源方便、快捷的数据库文档查询、生成工具