Open wmenjoy opened 4 years ago
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
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
安装系统
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
安装网络插件
curl https://docs.projectcalico.org/manifests/calico-etcd.yaml -o calico
a. 更新kubeadm b. 更新kubectl和kubelet c、升级其他控制节点
# 创建多镜像
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'
kubectl create deployment nginx --image nginx --dry-run -o yaml | sed 's/Deployment/DaemonSet/g;s/.*: {}//g;s/replicas: .*//g;' > 1.yaml
kubectl create secret generic test --from-literal=key=value --from-literal=man=p --dry-run -o yaml
kubectl create configmap key --from-literal=t=b -o yaml --dry-run
kubectl create serviceaccount key --dry-run -o yaml
# 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
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
kubectl set sa -f nginx-deployment.yaml serviceaccount1 --local --dry-run -o yaml
kubectl set image deployments,rc nginx=nginx:1.9.1 --all
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
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
资源
参考