add namespace

This commit is contained in:
2022-07-04 15:28:37 +08:00
parent bf482c193f
commit eadf98e33c
3 changed files with 26 additions and 2 deletions

View File

@@ -2,10 +2,11 @@ apiVersion: apps/v1 #与k8s集群版本有关使用 kubectl api-versions 即
kind: Deployment #该配置的类型,我们使用的是 Deployment kind: Deployment #该配置的类型,我们使用的是 Deployment
metadata: #译名为元数据,即 Deployment 的一些基本属性和信息 metadata: #译名为元数据,即 Deployment 的一些基本属性和信息
name: nginx-deployment #Deployment 的名称 name: nginx-deployment #Deployment 的名称
namespace: nginx
labels: #标签可以灵活定位一个或多个资源其中key和value均可自定义可以定义多组目前不需要理解 labels: #标签可以灵活定位一个或多个资源其中key和value均可自定义可以定义多组目前不需要理解
app: nginx #为该Deployment设置key为appvalue为nginx的标签 app: nginx #为该Deployment设置key为appvalue为nginx的标签
spec: #这是关于该Deployment的描述可以理解为你期待该Deployment在k8s中如何使用 spec: #这是关于该Deployment的描述可以理解为你期待该Deployment在k8s中如何使用
replicas: 1 #使用该Deployment创建一个应用程序实例 replicas: 3 #使用该Deployment创建一个应用程序实例
selector: #标签选择器,与上面的标签共同作用,目前不需要理解 selector: #标签选择器,与上面的标签共同作用,目前不需要理解
matchLabels: #选择包含标签app:nginx的资源 matchLabels: #选择包含标签app:nginx的资源
app: nginx app: nginx
@@ -16,4 +17,4 @@ spec: #这是关于该Deployment的描述可以理解为你期待该D
spec: #期望Pod实现的功能即在pod中部署 spec: #期望Pod实现的功能即在pod中部署
containers: #生成container与docker中的container是同一种 containers containers: #生成container与docker中的container是同一种 containers
- name: nginx #container的名称 - name: nginx #container的名称
image: nginx:1.7.9 #使用镜像nginx:1.7.9创建container该container默认80端口可访问 image: nginx:1.23.0 #使用镜像nginx:1.7.9创建container该container默认80端口可访问

View File

@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: nginx
labels:
name: nignx

View File

@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-service #Service 的名称
namespace: nginx
labels: #Service 自己的标签
app: nginx #为该 Service 设置 key 为 appvalue 为 nginx 的标签
spec: #这是关于该 Service 的定义,描述了 Service 如何选择 Pod如何被访问
selector: #标签选择器
app: nginx #选择包含标签 app:nginx 的 Pod
ports:
- name: nginx-port #端口的名字
protocol: TCP #协议类型 TCP/UDP
port: 80 #集群内的其他容器组可通过 80 端口访问 Service
nodePort: 32600 #通过任意节点的 32600 端口访问 Service
targetPort: 80 #将请求转发到匹配 Pod 的 80 端口
type: NodePort #Serive的类型ClusterIP/NodePort/LoaderBalancer