美文网首页
Kubernetes命令备忘录

Kubernetes命令备忘录

作者: Hiper | 来源:发表于2023-01-09 11:02 被阅读0次

    Docker相关

    # 拉取代码
    docker pull
    # 登录Docker Hub
    docker login
    # Commit和Push
    docker commit haha
    docker push xxx/haha:v1
    # 创建容器并运行 
    docker run -p 4000:80 --name haha nginx:latest
    # 进入容器
    docker exec -it haha /bin/sh
    # 查看运行容器的进程Id
    docker top haha
    # 停止容器
    docker stop haha
    # 启动容器
    docker start haha
    # 容器镜像列表
    docker images
    # 容器运行列表
    docker ps -a
    # 删除镜像
    docker rmi image-name
    # 删除运行容器
    docker rm container-name
    

    Kubectl相关

    # 获取列表
    kubectl get pods/deployment/secrets/configmaps
    # 从文件新建或更新配置
    kubectl apply -f xxx.yaml
    # 从文件删除配置
    kubectl delete -f xxx.yaml
    # 进入pods
    kubectl exec -it pod-name /bin/sh
    # 查看详情
    kubectl describe pod/deployment name
    

    配置文件

    Pods

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
    spec:
      shareProcessNamespace: true
      containers:
      - name: nginx
        image: nginx
      - name: shell
        image: busybox
        stdin: true
        tty: true
    

    Deployment

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            ports:
            - containerPort: 80
            volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: nginx-vol
          volumes:
          - name: nginx-vol
            emptyDir: {}
    

    相关文章

      网友评论

          本文标题:Kubernetes命令备忘录

          本文链接:https://www.haomeiwen.com/subject/gtbpcdtx.html