使用kubeadm初始化IPV4/IPV6集群 ======================= CentOS 配置YUM源 ============= ```shell cat < /etc/yum.repos.d/kubernetes.repo [kubernetes] name=kubernetes baseurl=https://mirrors.ustc.edu.cn/kubernetes/yum/repos/kubernetes-el7-$basearch enabled=1 EOF setenforce 0 yum install -y kubelet kubeadm kubectl # 如安装老版本 # yum install kubelet-1.16.9-0 kubeadm-1.16.9-0 kubectl-1.16.9-0 systemctl enable kubelet && systemctl start kubelet # 将 SELinux 设置为 permissive 模式(相当于将其禁用) sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config sudo systemctl enable --now kubelet ``` Ubuntu 配置APT源 ============= ```shell curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - cat </etc/apt/sources.list.d/kubernetes.list deb https://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main EOF apt-get update apt-get install -y kubelet kubeadm kubectl # 如安装老版本 # apt install kubelet=1.23.6-00 kubeadm=1.23.6-00 kubectl=1.23.6-00 ``` 配置containerd ============ ```shell wget https://github.com/containerd/containerd/releases/download/v1.6.4/cri-containerd-cni-1.6.4-linux-amd64.tar.gz #解压 tar -C / -xzf cri-containerd-cni-1.6.4-linux-amd64.tar.gz #创建服务启动文件 cat > /etc/systemd/system/containerd.service < /etc/hosts < --discovery-token-ca-cert-hash sha256:2ade8c834a41cc1960993a600c89fa4bb86e3594f82e09bcd42633d4defbda0d [preflight] Running pre-flight checks [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml' [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Starting the kubelet [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details. Run 'kubectl get nodes' on the control-plane to see this node join the cluster. root@k8s-node01:~#  root@k8s-node02:~# kubeadm join 10.0.0.21:6443 --token qf3z22.qwtqieutbkik6dy4 \ > --discovery-token-ca-cert-hash sha256:2ade8c834a41cc1960993a600c89fa4bb86e3594f82e09bcd42633d4defbda0d [preflight] Running pre-flight checks [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml' [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Starting the kubelet [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details. Run 'kubectl get nodes' on the control-plane to see this node join the cluster. root@k8s-node02:~#  ``` 查看集群 ==== ```shell root@k8s-master01:~# kubectl  get node NAME           STATUS   ROLES           AGE    VERSION k8s-master01   Ready    control-plane   111s   v1.24.0 k8s-node01     Ready              82s    v1.24.0 k8s-node02     Ready              92s    v1.24.0 root@k8s-master01:~#  root@k8s-master01:~#  root@k8s-master01:~# kubectl  get pod -A NAMESPACE     NAME                                   READY   STATUS    RESTARTS   AGE kube-system   coredns-bc77466fc-jxkpv                1/1     Running   0          83s kube-system   coredns-bc77466fc-nrc9l                1/1     Running   0          83s kube-system   etcd-k8s-master01                      1/1     Running   0          87s kube-system   kube-apiserver-k8s-master01            1/1     Running   0          89s kube-system   kube-controller-manager-k8s-master01   1/1     Running   0          87s kube-system   kube-proxy-2lgrn                       1/1     Running   0          83s kube-system   kube-proxy-69p9r                       1/1     Running   0          47s kube-system   kube-proxy-g58m2                       1/1     Running   0          42s kube-system   kube-scheduler-k8s-master01            1/1     Running   0          87s root@k8s-master01:~#  ``` 配置calico ======== ```shell wget https://raw.githubusercontent.com/cby-chen/Kubernetes/main/yaml/calico-ipv6.yaml # vim calico-ipv6.yaml # calico-config ConfigMap处     "ipam": {         "type": "calico-ipam",         "assign_ipv4": "true",         "assign_ipv6": "true"     },     - name: IP       value: "autodetect"     - name: IP6       value: "autodetect"     - name: CALICO_IPV4POOL_CIDR       value: "172.16.0.0/12"     - name: CALICO_IPV6POOL_CIDR       value: "fc00::/48"     - name: FELIX_IPV6SUPPORT       value: "true" kubectl  apply -f calico-ipv6.yaml  ``` 测试IPV6 ====== ```shell root@k8s-master01:~# cat cby.yaml  apiVersion: apps/v1 kind: Deployment metadata:   name: chenby spec:   replicas: 3   selector:     matchLabels:       app: chenby   template:     metadata:       labels:         app: chenby     spec:       containers:       - name: chenby         image: nginx         resources:           limits:             memory: "128Mi"             cpu: "500m"         ports:         - containerPort: 80 --- apiVersion: v1 kind: Service metadata:   name: chenby spec:   ipFamilyPolicy: PreferDualStack   ipFamilies:   - IPv6   - IPv4   type: NodePort   selector:     app: chenby   ports:   - port: 80     targetPort: 80 kubectl  apply -f cby.yaml  root@k8s-master01:~# kubectl  get pod  NAME                      READY   STATUS    RESTARTS   AGE chenby-57479d5997-6pfzg   1/1     Running   0          6m chenby-57479d5997-jjwpk   1/1     Running   0          6m chenby-57479d5997-pzrkc   1/1     Running   0          6m root@k8s-master01:~# kubectl  get svc NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE chenby       NodePort    fd00::f816           80:30265/TCP   6m7s kubernetes   ClusterIP   10.96.0.1            443/TCP        168m root@k8s-master01:~# curl -I http://[2408:8207:78ce:7561::21]:30265/ HTTP/1.1 200 OK Server: nginx/1.21.6 Date: Wed, 11 May 2022 07:01:43 GMT Content-Type: text/html Content-Length: 615 Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT Connection: keep-alive ETag: "61f01158-267" Accept-Ranges: bytes root@k8s-master01:~# curl -I http://10.0.0.21:30265/ HTTP/1.1 200 OK Server: nginx/1.21.6 Date: Wed, 11 May 2022 07:01:54 GMT Content-Type: text/html Content-Length: 615 Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT Connection: keep-alive ETag: "61f01158-267" Accept-Ranges: bytes ``` > **关于** > > https://www.oiox.cn/ > > https://www.oiox.cn/index.php/start-page.html > > **CSDN、GitHub、知乎、开源中国、思否、掘金、简书、华为云、阿里云、腾讯云、哔哩哔哩、今日头条、新浪微博、个人博客** > > **全网可搜《小陈运维》** > > **文章主要发布于微信公众号:《Linux运维交流社区》**