K8S-应用部署

2024-01-08 14:29:40

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
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。