$ vi /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ xenial main
deb-src http://mirrors.163.com/ubuntu/ xenial main
deb http://mirrors.163.com/ubuntu/ xenial-updates main
deb-src http://mirrors.163.com/ubuntu/ xenial-updates main
deb http://mirrors.163.com/ubuntu/ xenial universe
deb-src http://mirrors.163.com/ubuntu/ xenial universe
deb http://mirrors.163.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.163.com/ubuntu/ xenial-updates universe
deb http://mirrors.163.com/ubuntu/ xenial-security main
deb-src http://mirrors.163.com/ubuntu/ xenial-security main
deb http://mirrors.163.com/ubuntu/ xenial-security universe
deb-src http://mirrors.163.com/ubuntu/ xenial-security universe
docker tag docker.io/mirrorgooglecontainers/kube-apiserver:v1.14.1 k8s.gcr.io/kube-apiserver:v1.14.1
docker tag docker.io/mirrorgooglecontainers/kube-controller-manager:v1.14.1 k8s.gcr.io/kube-controller-manager:v1.14.1
docker tag docker.io/mirrorgooglecontainers/kube-scheduler:v1.14.1 k8s.gcr.io/kube-scheduler:v1.14.1
docker tag docker.io/mirrorgooglecontainers/kube-proxy:v1.14.1 k8s.gcr.io/kube-proxy:v1.14.1
docker tag docker.io/mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag docker.io/mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag docker.io/coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
# 安装flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
下面这个存在问题,不要用(被坑了好久)
~~kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-legacy.yml~~
# 安装Dashboard:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
Then you can join any number of worker nodes by running the following on each as root:
# 子节点加入master节点的命令:
kubeadm join 172.30.0.2:6443 --token fwu0at.stz02oag8qdr7bte --discovery-token-ca-cert-hash sha256:44a090e032f3623c84a21df5ef963fd83d8932ed92f5c3fb307e9b77890121ee
检验两个节点是否已经加入到k8s集群
运行kubectl get nodes命令,获得k8s集群中存在的节点,输出如下:
1234
NAME STATUS ROLES AGE VERSION
ubuntu-s-master Ready master 34m v1.11.2
ubuntu-s-node1 NotReady <none> 10s v1.11.2
ubuntu-s-node2 Ready <none> 5m v1.11.2
4.在k8s集群中运行httpd服务
4.1 部署httpd程序
运行下面命令简单地部署httpd程序
123
kubectl run httpd-app --image=httpd --replicas=2
# 或者
kubectl run nginx-deploy –image=nginx –port=80 –replicas=1
4.2查看部署结果:
123
root@ubuntu-s-master:~# kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
httpd-app 2 2 2 2 1m
查看httpd在集群内的ip地址
1234
root@ubuntu-s-master:~# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
httpd-app-7bdd9f8ff4-hhszt 1/1 Running 0 6m 10.244.2.2 ubuntu-s-node1 <none>
httpd-app-7bdd9f8ff4-qp7wl 1/1 Running 0 6m 10.244.1.4 ubuntu-s-node2 <none>