当前位置:网站首页>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)
边栏推荐
- 华为游戏初始化init失败,返回错误码907135000
- Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
- Write an open source, convenient and fast database document query and generation tool with WPF
- Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
- 实现一个Prometheus exporter
- Gameframework eating guide
- Cache problems after app release
- JS find the next adjacent element of the number in the array
- Image acquisition and playback of coaxpress high speed camera based on pxie interface
- [live broadcast appointment] database obcp certification comprehensive upgrade open class
猜你喜欢

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

11、用户、组和权限(1)

1. "Create your own NFT collections and publish a Web3 application to show them." what is NFT

【直播预约】数据库OBCP认证全面升级公开课

Improve yolov5 with gsconv+slim neck to maximize performance!

After studying 11 kinds of real-time chat software, I found that they all have these functions

Li Kou daily question - Day 32 -589 N × Preorder traversal of tree

2. Create your own NFT collections and publish a Web3 application to show them start and run your local environment

Altair HyperWorks 2022 software installation package and installation tutorial

Leetcode203 remove linked list elements
随机推荐
宏观视角看抖音全生态
Clean up system cache and free memory under Linux
Netease games, radical going to sea
如何使用物联网低代码平台进行个人设置?
Halcon image calibration enables subsequent image processing to become the same as the template image
磁盘的基本知识和基本命令
Lumiprobe 活性染料丨吲哚菁绿说明书
Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Love business in Little Red Book
太爱速M源码搭建,巅峰小店APP溢价寄卖源码分享
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
Games202 operation 0 - environment building process & solving problems encountered
中英说明书丨人可溶性晚期糖基化终末产物受体(sRAGE)Elisa试剂盒
M91快速霍尔测量仪—在更短的时间内进行更好的测量
华为云专家详解GaussDB(for MySQL)新特性
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书
用WPF写一款开源方便、快捷的数据库文档查询、生成工具
Stanford, salesforce|maskvit: masked vision pre training for video prediction