k8s命令补全

## 需要安装命令补全工具

source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc

创建nginx_pod

cat nginx.yaml

apiVersion: v1                    ## api版本
kind: Pod						## 资源类型
metadata:
  name: nginx-pod				## Pod 名称
  labels:						## 标签
    app: test
spec:							## 容器要求
  containers:
  - name: mynginx				## 容器名称
    image: nginx				## 镜像
    imagePullPolicy: IfNotPresent	## 镜像拉取策略
    ports:						## 容器端口
    - containerPort: 80

kubectl apply -f nginx.yaml            ## 使用yaml创建pod

kubectl get pods                         ## 查看default命名空间下的pod

创建nginx_deploy

cat nginx_deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
    name: hello-deployment		## 指定deployment名字
spec:
    replicas: 4					## 4个副本 
    selector:					## 选择器(标签选择器)
        matchLabels:			## 匹配的标签
            name: hello-deployment		## 维持具有name: hello-deployment标签的pod(与template内labels标签匹配)
    template:		
         metadata:
             labels:
                name: hello-deployment
         spec:					## 创建pod
            containers:
            - name: webserver
              image: nginx:1.14
              ports:
              - containerPort: 80

kubectl apply -f nginx_deploy.yaml

kubectl get pods  ## 查看pod有4个副本

kubectl get deployment    ## 查看default命名空间下的deploy

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐