wmenjoy / awesome-knowleges

汇总有用的知识
38 stars 7 forks source link

k8s考试 #68

Open wmenjoy opened 4 years ago

wmenjoy commented 4 years ago

资源

参考

  1. 2020年CKA考试最新最全指南 - 知乎
  2. CKA(Certified Kubernetes Administrator) 學習資源整理 | 小信豬的原始部落
  3. cka真题
  4. https://learnk8s.io/news
wmenjoy commented 3 years ago

kubeadm 相关

安装集群

  1. 安装工具
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
  1. 配置系统
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
  1. 安装系统

    kubeadm init

    初始化工作环境

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
  2. 安装网络插件

    curl https://docs.projectcalico.org/manifests/calico-etcd.yaml -o calico

升级集群

  1. 升级控制节点

a. 更新kubeadm b. 更新kubectl和kubelet c、升级其他控制节点

  1. 升级work节点 a. 更新kubeadm b. 更新kubectl和kubelet

新增节点

  1. 使用token kubeadm join --token 2、使用tls bootstrapping

参考

  1. Creating a cluster with kubeadm | Kubernetes
  2. Installing kubeadm | Kubernetes
wmenjoy commented 3 years ago

kubectl 使用

资源创建

  1. deployment
    # 创建多镜像
    kubectl create deployment nginx --image nginx,redis  --dry-run -o yaml
    kubectl create deployment nginx --image nginx  --dry-run -o yaml
    # 多实例
    kubectl create deployment nginx --image nginx,redis  --dry-run -o yaml |sed 's/replicas:.*/replicas: 7/g'
  2. daemonset
    kubectl create deployment nginx --image nginx  --dry-run -o yaml | sed 's/Deployment/DaemonSet/g;s/.*: {}//g;s/replicas: .*//g;'  > 1.yaml
  3. secret
    kubectl create secret generic test --from-literal=key=value --from-literal=man=p --dry-run -o yaml
  4. configmap
    kubectl create configmap key --from-literal=t=b -o yaml --dry-run
  5. serviceaccount
    kubectl create serviceaccount key --dry-run -o yaml
  6. service
# nodeport
kubectl create service nodeport t --tcp=80:80 --node-port=10047 --dry-run -o yaml
kubectl expose deployment abc --port 80 --type NodePort --name t --dry-run -o yaml
# clusterIp
kubectl expose deployment abc --port 80  --name t --dry-run -o yaml
kubectl create service clusterip t --tcp 80:80 --dry-run -o yaml
## loadbalance
kubectl create service loadbalancer t --tcp 80:80 --dry-run -o yaml
kubectl expose deployment abc --port 80 --type LoadBalancer --dry-run -o yaml --name t
## external name
kubectl create service externalname t --external-name abc.default -o yaml --dry-run
## headless
kubectl create service clusterip t --clusterip=None --tcp=80:80 --dry-run -o yaml
  1. role 和clusterrole
    kubectl create role my-role --verb create --resource pods --dry-run -o yaml
    kubectl create clusterrole my-role --verb create --resource pods --dry-run -o yaml

    8 rolebinding 和clusterrolebinding

    kubectl create rolebinding l --clusterrole key --role key --serviceaccount default:key  --dry-run -o yaml

    9 quota

    kubectl create quota t --hard=cpu=1,memory=1G,pods=2,services=3,replicationcontrollers=2,resourcequotas=1,secrets=5,persistentvolumeclaims=10 --dry-run -o yaml

    10 pod

    kubectl run pod  --image nginx  --dry-run -o yaml --command -- ls -l key=v --env p=t

    更新资源

  2. 设置账号
    kubectl set sa -f nginx-deployment.yaml serviceaccount1 --local --dry-run -o yaml
  3. 设置镜像
    kubectl set image deployments,rc nginx=nginx:1.9.1 --all
  4. 设置资源
    kubectl set resources deployment nginx -c=nginx --limits=cpu=200m,memory=512Mi
    kubectl set resources deployment nginx --limits=cpu=0,memory=0 --requests=cpu=0,memory=0
  5. 更新用户信息
    kubectl set subject clusterrolebinding admin --serviceaccount=namespace:serviceaccount1
    kubectl set subject rolebinding admin --user=user1 --user=user2 --group=group1

    5、标签、env和注释

    kubectl annotate pods foo description='my frontend running nginx' --resource-version=1
    kubectl label pods foo  description='my frontend running nginx' --resource-version=1
    kubectl set env --from=secret/mysecret deployment/myapp
    kubectl set env --from=configmap/myconfigmap --prefix=MYSQL_ deployment/myapp
    kubectl set env deployment/registry STORAGE_DIR=/local
wmenjoy commented 3 years ago

课程培训

  1. #100DaysOfKubernetes
wmenjoy commented 3 years ago

理解k8s

  1. 47 Things To Become a Kubernetes Expert - Blog of @ymmt2005
wmenjoy commented 3 years ago

其他资源

  1. Blog of @ymmt2005
wmenjoy commented 3 years ago

测试环境搭建

  1. ManagedKube/kubernetes-development-environment-in-a-box: This project is geared toward running multiple isolated KinD cluster on a single instance
wmenjoy commented 3 years ago

入门文章

  1. Kubernetes Cheat Sheet | Mirantis