当前位置:网站首页>[cloud native] 2.3 kubernetes core practice (Part 1)

[cloud native] 2.3 kubernetes core practice (Part 1)

2022-06-27 08:26:00 Procedural ape chase

  hello ~ Hello, everyone , In the previous article, we deployed the cluster and set up the visual interface , Let's move on to the core practical part .

 

  Personal home page : Personal home page ​​​​​             

  Series column :【 Cloud native series 】

Articles related to this article :            

1.5【 Cloud native 】 Docker The advanced combat 【 Cloud native 】1.5 Docker The advanced combat _ Program ape chase blog -CSDN Blog _idea link docker
2.1【 Cloud native 】 Kubernetes Basic concepts 【 Cloud native 】2.1 Kubernetes Basic concepts _ Program ape chase blog -CSDN Blog
2.2【 Cloud native 】 kubeadm Create clusters 【 Cloud native 】2.2 kubeadm Create clusters _ Program ape chase blog -CSDN Blog

Catalog

One 、 operation Namespace

Two 、 understand Pod 

3、 ... and 、 establish Pod

Four 、 Multiple containers Pod details

5、 ... and 、 Use Deployment Deploy the application


One 、 operation Namespace

Our resource creation methods include command line and YAML.Namespace( The name space ) It is used to isolate resources . notes : The name space , It is used to isolate and partition cluster resources . By default, only resources are isolated , Do not isolate the network . The general system comes with :kube-node-lease、kube-public、kube-system  etc. , The default is default. Of course, we can also see from the command line (kubectl get ns And  kubectl get pods -A). Before operation, we usually need to build a .yaml file .

Create space

kubectl create ns hello

Delete space

kubectl delete ns hello

 

Two 、 understand Pod 

Pod Is a set of containers in operation , yes kubernetes The smallest unit applied in .

Pod What does it have to do with the container ? 

We have three nodes , Also install Docker( Provide a containerized operating environment , We call it CRI【Container Runtime Interface】), Add three applications ( In a containerized way ),k8s It is to manage these containers , Then add... To the application Pod, It can be understood as encapsulating them , That's why I have a sentence —— yes kubernetes The smallest unit applied in .(Pod It can run multiple containers )

  3、 ... and 、 establish Pod

With the above concept , This is what we are going to create Pod, So it's the same as before , We use commands .

kubectl run mynginx --image=nginx

We have seen so much in detail , Everyone is familiar with this format ?kubectl run + name + Mirror name

Once created, you can use  kubectl get pod Check it out. (-A Is to view all )

  Check the running container ( Use in batch input )

docker ps|grep mynginx

 

describe Pod

kubectl describe pod  Your own Pod name 


Delete  Pod

kubectl delete pod Pod name 


see Pod Operation log of

kubectl logs Pod name 

How to create a configuration file Pod Well ?

Input vi pod. yaml, Then enter the following code ( Remember to exit and save )

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: mynginx
  name: mynginx
#  namespace: default
spec:
  containers:
  - image: nginx
    name: mynginx


kubectl apply -f pod. yaml Let's apply

Every Pod - k8s Will be assigned a ip

kubectl get pod -owide


Use Pod Of ip + pod The port in which the container runs

curl 192.168.169.136

  Four 、 Multiple containers Pod details

In our last article, we talked about using visual interfaces , Here, let's take a look at the use of the command line and interface .

Again, we create a yaml file ——vi mul ticontainer-pod.yaml, Then paste directly .

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: mynginx
  name: mynginx
#  namespace: default
spec:
  containers:
  - image: nginx
    name: mynginx

 

The visual interface is very friendly to operate , For example, it is very convenient to view resource information 、 state 、 Events, etc. .  After downloading , Use curl + ip You can print some htnl Code .

  We enter  nginx Container come , visit tomcat——curl + Native address :8080, In the same way tomcat Inside visit nginx It only needs tomcat——curl + Native address :80, That's all right. ( Very gingko like ).

 

  5、 ... and 、 Use Deployment Deploy the application

Deployment effect : control Pod, send Pod Have multiple copies , self-healing , Ability to expand, shrink, etc ( Not afraid of machine crash 、 Swing machine , With self recovery function ).

In a word , It's used to control Pod Of .

Create deployment

kubectl create deployment mytomcat --image=tomcat:8.5.68

  establish 3 Copies

kubectl create deployment my-dep --image=nginx --replicas=3

 

 

The next preview continues 2.4 Kubernetes Core combat

 ( Please pay attention to ) Ongoing update ……

原网站

版权声明
本文为[Procedural ape chase]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270807569710.html