learning_notes

学习笔记

View project on GitHub

命令

  1. k8s拉去私有仓库image

     kubectl create secret docker-registry registry-secret --docker-server=registry.cn-shenzhen.aliyuncs.com --docker-username=mengqingfang@*** --docker-password= --docker-email=mengqingfang@zingsq -n default
        
     --docker-server: 仓库地址
     --docker-username: 仓库登陆账号
     --docker-password: 仓库登陆密码
     --docker-email: 邮件地址(选填)
     -n 命名空间
        
        
        ... 
         spec:
           serviceAccountName: test
           imagePullSecrets:
           - name: registry-secret
           containers:
           - name: test
             image: registry.cn-shenzhen.aliyuncs.com/koza/test:latest
    
     kubectl create secret docker-registry registry-secret --docker-server=registry.cn-shenzhen.aliyuncs.com --docker-username=hukun@zingsq --docker-password=hukun123 --docker-email=hukun@zingsq.cn -n default
    
  2. 强制删除一个pod

    kubectl delete pod xxxxxx --grace-period=0 --force
    
  3. 命令行补全

    source <(kubectl completion bash)
    echo "source <(kubectl completion bash)" >> ~/.bashrc
    
  4. 强制重启一个pod

     kubectl get pod install-helm  -n gitlab-managed-apps -o yaml | kubectl replace --force -f -
    
  5. k8s中pod设置访问外网

    dnsPolicy: Default

     apiVersion: apps/v1
     kind: Deployment
     metadata:
       name: alpine
     spec:
       selector:
         matchLabels:
           app: alpine
       replicas: 1
       template:
         metadata:
           labels:
             app: alpine
         spec:
           containers:
           - image: alpine
             name: alpine
             command: ["top","-b"]
           dnsPolicy: Default