https://blog.csdn.net/jinglexy/article/details/79813546node
在官網web上進行kubenetes測試:
kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080nginx
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port=8080
kubectl scale --replicas=3 deployment/kubernetes-bootcamp
kubectl scale --replicas=2 deployment/kubernetes-bootcampgit
kubectl get deployment
kubectl get pod
kubectl get servicegithub
kubectl set image deployment/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
curl host01:30692 根據上面service的端口
curl host01:30692
kubectl rollout undo deployment/kubernetes-bootcamp
curl host01:30692 根據上面service的端口
curl host01:30692web
======================================================================================docker
(1)安裝kubelet, kubeadm和kubectl(master和slave都須要執行)
https://kubernetes.io/docs/setup/independent/install-kubeadm/
各個節點:
master: 192.168.7.163
slave1: 192.168.7.164
slave2: 192.168.7.165
把/etc/fstab裏面的swap幹掉,而後在~/.bashrc添加sudo /sbin/swapoff -aapi
(2)初始化master(若是步驟失敗,執行kubeadm reset)
kubeadm init --apiserver-advertise-address 192.168.7.163 --pod-network-cidr=10.244.0.0/16
輸出結果裏面的最下面的一條kubeadm join記下來,後面會用到,例如:
kubeadm join 192.168.7.163:6443 --token gws3w0.vftvaze6zwe0vzhm --discovery-token-ca-cert-hash sha256:3adf3ee2350412b4ae434da02edcbcd119fa9da306a20758b8be1261716c527f
若是失敗或者之後更改master參數:
sudo kubeadm reset
sudo docker stop $(docker ps |grep k8s_ | awk '{print $1}')
sudo docker rm $(docker ps |grep k8s_ | awk '{print $1}')
sudo rm -rf /var/lib/kubelet/
docker ps -a務必沒有k8s_開頭的容器bash
(3)master下配置kubectl環境
mkdir ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
sudo chown wyt:wyt ~/.kube/config
sudo chmod 777 ~/.kube/config
sudo bash -c "kubectl completion bash > /etc/bash_completion.d/kubectl"
sudo bash -c "kubeadm completion bash > /etc/bash_completion.d/kubeadm"網絡
(4)master下配置pod網絡(安裝flannel)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlapp
(5)slave初始化(若是有多個slave,每一個slave都要執行)
執行上面的kubeadm join命令,可能會報一個錯誤,緣由是/var/run/dockershim.sock不存在,由於沒有建立slave因此不存在,這是個無限死循環,解決方法:
在kubeadm join後面加一個參數: --ignore-preflight-errors=cri
(6)slave下配置kubectl環境
mkdir ~/.kube
sudo cp /etc/kubernetes/kubelet.conf ~/.kube/config
sudo chown wyt:wyt ~/.kube/config
sudo chmod 777 ~/.kube/config
sudo bash -c "kubectl completion bash > /etc/bash_completion.d/kubectl"
sudo bash -c "kubeadm completion bash > /etc/bash_completion.d/kubeadm"
(6)相關命令
kubectl get pod --all-namespaces
kubectl get node
kubectl get deployment
(7)deployment
kubectl run nginx-deployment --image=nginx:1.7.9 --replicas=2
而後用kubectl get deployment/pod查看狀況,發現pod狀態是ContainerCreating,
悲了個催的,而後調試:
kubectl describe deployment nginx-deployment
kubectl describe pod nginx-deployment-6b5c99b6fd-nvjkg
提示:FailedCreatePodSandBox,發現是前面pod-network-cidr設置問題
搞定後:經過ifconfig命令,master主機網段是10.244.0.x,slave1網段是10.244.1.x
kubectl get pod --all-namespaces必須所有running,不然後面的沒有意義
(8)yml示例:
https://gist.github.com/wjx0912/5941737974edc91c462f05e8a0a50dce
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
(9)我整理的一些yml
https://gist.github.com/wjx0912
(10)接下來須要學習的要點建立service,dns訪問service,外網訪問service,回滾,volume管理,helm包管理,網絡部署,dashboard,集羣監控,日誌