ITeye博客

K8S 创建pod,service, deployment

mukeliang728 · 2021-11-05 14:58 · k8s · 开源软件 · Markdown

  • 编写 Nginx Pod 的 yaml

    apiVersion: v1
    kind: Pod
    metadata:
      name: my-nginx
    spec:
      containers:
      - image: nginx
        name: my-nginx
    
  • 创建 Nginx Pod

    kubectl apply -f nginx.yaml  
    
  • 查看 Pod 情况

    kubectl get po
    kubectl describ pod my-nginx
    
  • 创建 NodePort 类型的 service

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: nginx
      name: nginx-deployment
    spec:
      ports:
      - port: 80
        name: nginx-service80
        protocol: TCP
        targetPort: 80
        nodePort: 30001  
      selector:
        app: nginx
      type: NodePort 
    

    创建 Deployment

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
      labels:
        app: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.14.2
            ports:
            - containerPort: 80
    
    

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。