kubenetes安装记录和要点
https://blog.csdn.net/jinglexy/article/details/79813546
在官网web上进行kubenetes测试:
kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port=8080
kubectl scale --replicas=3 deployment/kubernetes-bootcamp
kubectl scale --replicas=2 deployment/kubernetes-bootcamp
kubectl get deployment
kubectl get pod
kubectl get service
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:30692
======================================================================================
(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 -a
(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_开头的容器
(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.yml
(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,集群监控,日志