配置位于proxy内的k8s kubeadm cluster

Set up proxy for kubeadm

.bashrc中添加:

export http_proxy=http://127.0.0.1:3128/
export HTTP_PROXY=http://127.0.0.1:3128/
export https_proxy=$http_proxy
export HTTPS_PROXY=$http_proxy
printf -v lan '%s,' 10.221.117.198   # ip of the machine
printf -v pool '%s,' 192.168.0.{1..253}
printf -v service '%s,' 10.96.0.{1..253}
export no_proxy="${lan%,},${service%,},${pool%,},127.0.0.1";
export NO_PROXY=$no_proxy

Set up proxy for containerd

sudo nano /etc/systemd/system/containerd.service.d/http-proxy.conf :

[Service]
Environment="HTTP_PROXY=http://10.206.133.47:3128/"
Environment="HTTPS_PROXY=http://10.206.133.47:3128/"

Set up proxy for docker

Create a new directory for docker service configuration:

mkdir -p /etc/systemd/system/docker.service.d

Create and edit /etc/systemd/system/docker.service.d/http-proxy.conf:

[Service]
Environment="HTTP_PROXY=http://PROXY-IP:PROXY-PORT"
Environment="HTTPS_PROXY=http://PROXY-IP:PROXY-PORT"

初始化 kubadm

kubeadm init --apiserver-advertise-address=ip_of_the_machine --service-cidr=10.96.0.0/16 --cri-socket /run/containerd/containerd.sock --pod-network-cidr=10.244.0.0/16

Untain master node

kubectl taint node mymasternode  node-role.kubernetes.io/control-plane:NoSchedule-

Add CNI to K8S

kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

实操

启动 cluster之前

yaoxin@master:~/Project/Quark$ export HTTP_PROXY=$http_proxy
yaoxin@master:~/Project/Quark$ export https_proxy=$http_proxy
yaoxin@master:~/Project/Quark$ export HTTPS_PROXY=$http_proxy
yaoxin@master:~/Project/Quark$ printf -v lan '%s,' 10.206.133.76
yaoxin@master:~/Project/Quark$ printf -v pool '%s,' 10.204.0.{1..253}
yaoxin@master:~/Project/Quark$ printf -v service '%s,' 10.96.0.{1..253}
yaoxin@master:~/Project/Quark$ export no_proxy="${lan%,},${service%,},${pool%,},127.0.0.1";
yaoxin@master:~/Project/Quark$ export NO_PROXY=$no_proxy
yaoxin@master:~/Project/Quark$ sudo kubeadm init --cri-socket=/var/run/containerd/containerd.sock --pod-network-cidr=10.244.0.0/16

启动 cluster之后

yaoxin@master:~/Project/Quark$ mkdir -p $HOME/.kube
yaoxin@master:~/Project/Quark$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
cp: overwrite '/home/yaoxin/.kube/config'? y
yaoxin@master:~/Project/Quark$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
yaoxin@master:~/Project/Quark$ kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
namespace/kube-flannel created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created
yaoxin@master:~/Project/Quark$ cat <<EOF | kubectl apply -f -
> apiVersion: node.k8s.io/v1
> kind: RuntimeClass
> metadata:
>   name: quark
> handler: quark
> EOF
runtimeclass.node.k8s.io/quark created
yaoxin@master:~/Project/Quark$ kubectl taint node mymasternode  node-role.kubernetes.io/control-plane:NoSchedule-
Error from server (NotFound): nodes "mymasternode" not found
yaoxin@master:~/Project/Quark$ 
yaoxin@master:~/Project/Quark$ kubectl taint node master  node-role.kubernetes.io/control-plane:NoSchedule-
node/master untainted

你可能感兴趣的:(linux,k8s,kubernetes,docker,容器)