0


K8S-应用部署

1 应用管理解读

image.png

2 应用部署实践

资源对象管理关系

image.png

资源对象管理实践

手工方式:
kubectl run pod名称 --image=image地址
资源清单方式:
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: my-pod
  name: my-pod
spec:
  containers:
  - image: kubernetes-register.sswang.com/sswang/nginx
    name: my-pod

deployment资源实践

nginx-proxy应用的配置清单文件
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sswang-nginx-proxy
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: kubernetes-register.sswang.com/sswang/nginx
        ports:
        - containerPort: 80
nginx-web 的资源清单文件
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sswang-nginx-web
  labels:
    app: nginx-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-web
  template:
    metadata:
      labels:
        app: nginx-web
    spec:
      containers:
      - name: nginx
        image: kubernetes-register.sswang.com/sswang/nginx_web:v0.1
        ports:
        - containerPort: 80
tomcat-web 的资源清单文件
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sswang-tomcat-web
  labels:
    app: tomcat-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat-web
  template:
    metadata:
      labels:
        app: tomcat-web
    spec:
      containers:
      - name: tomcat
        image: kubernetes-register.sswang.com/sswang/tomcat_web:v0.1
        ports:
        - containerPort: 8080

3 应用管理实践

资源对象隔离

namespace资源对象实践
apiVersion: v1
kind: Namespace
metadata:
  name: my-ns
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sswang-tomcat-web
  namespace: my-ns
  labels:
    app: tomcat-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat-web
  template:
    metadata:
      labels:
        app: tomcat-web
    spec:
      containers:
      - name: tomcat
        image: kubernetes-register.sswang.com/sswang/tomcat_web:v0.1
        ports:
        - containerPort: 8080

资源对象的扩缩容

资源对象扩缩容
kubectl scale deployment 资源对象名称 --replicas=目标数量 deployment/mysql

修改应用镜像版本
kubectl set image deployment 资源对象名称 容器名称=镜像名称

本文转载自: https://blog.csdn.net/qq_44534541/article/details/135434314
版权归原作者 会飞的土拨鼠呀 所有, 如有侵权,请联系我们删除。

“K8S-应用部署”的评论:

还没有评论