{"id":15,"date":"2022-03-16T01:33:16","date_gmt":"2022-03-15T17:33:16","guid":{"rendered":"https:\/\/maoyulong.club:30443\/?p=15"},"modified":"2022-03-16T01:42:41","modified_gmt":"2022-03-15T17:42:41","slug":"k8s-%e5%bc%80%e5%90%afipv4-v6-%e5%8f%8c%e6%a0%88","status":"publish","type":"post","link":"https:\/\/blog.maoyulong.club\/?p=15","title":{"rendered":"k8s \u5f00\u542fipv4\/v6 \u53cc\u6808"},"content":{"rendered":"<p>sealos\u8fdb\u884ck8s\u5b89\u88c5\u4e4b\u540e\u7684\u96c6\u7fa4\uff0c\u672c\u8eab\u662f\u6ca1\u6709ipv6\u652f\u6301\u7684\uff0c\u4e3a\u4e86\u80fd\u5916\u90e8ipv6\u8bbf\u95ee\uff0c\u6211\u4eec\u9700\u8981\u8ba9svc\u548cpod\u8fdb\u884c\u4e00\u4e2aipv6\u652f\u6301\uff08\u5f53\u7136\u53ef\u4ee5\u5728\u5916\u90e8\u6dfb\u52a0nginx\u7b49\u65b9\u6848\u89e3\u51b3\uff09<\/p>\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u5c06\u7cfb\u7edf\u7684ipv6\u8f6c\u53d1\u6253\u5f00<\/p>\n<pre><code>net.ipv6.conf.all.disable_ipv6 = 0\nnet.ipv6.conf.default.disable_ipv6 = 0\nnet.ipv6.conf.lo.disable_ipv6 = 0\nnet.ipv6.conf.all.forwarding=1\n<\/code><\/pre>\n<pre><code>sysctl -p\n<\/code><\/pre>\n<h2 id=\"k8s-\u542f\u7528\u53cc\u6808\">k8s \u542f\u7528\u53cc\u6808<\/h2>\n<p>\u4e4b\u540e\u5f00\u59cb\u914d\u7f6ek8s\u8fd9\u8fb9<\/p>\n<blockquote><p>\u4ece 1.21 \u5f00\u59cb IPv4\/IPv6 \u53cc\u534f\u8bae\u6808\u9ed8\u8ba4\u4e3a\u542f\u7528\u72b6\u6001\u3002 \u4f60\u53ef\u4ee5\u5728\u5fc5\u8981\u7684\u65f6\u5019\u901a\u8fc7\u4e3a kube-apiserver\u3001kube-controller-manager\u3001kubelet \u548c kube-proxy \u547d\u4ee4\u884c\u8bbe\u7f6e <code>--feature-gates=\"IPv6DualStack=false\"<\/code> \u6765\u7981\u7528 \u6b64\u7279\u6027\u3002<\/p><\/blockquote>\n<p>\u5728\u4e0b\u5217\u7ec4\u4ef6\u4e2d\u591a\u6dfb\u52a0\u4e00\u4e2aipv6 cidr\uff0c\u53ef\u4ee5\u53c2\u7167\u8fd9\u4e2a\u7528\u4f8b<\/p>\n<ul>\n<li>kube-apiserver:\n<ul>\n<li><code>--service-cluster-ip-range=&lt;IPv4 CIDR&gt;,fd00::\/108<\/code><\/li>\n<\/ul>\n<\/li>\n<li>kube-controller-manager:\n<ul>\n<li><code>--cluster-cidr=&lt;IPv4 CIDR&gt;,fc00::\/48<\/code><\/li>\n<li><code>--service-cluster-ip-range=&lt;IPv4 CIDR&gt;,fd00::\/108<\/code><\/li>\n<li><code>--node-cidr-mask-size-ipv4=24<\/code><\/li>\n<li><code>--node-cidr-mask-size-ipv6=64<\/code><\/li>\n<\/ul>\n<\/li>\n<li>kube-proxy:\n<ul>\n<li>kubectl -n kube-system edit cm kube-proxy<\/li>\n<li>data\n<ul>\n<li>config.conf :\n<ul>\n<li>featureGates:\n<ul>\n<li>IPv6DualStack: true<\/li>\n<\/ul>\n<\/li>\n<li>clusterCIDR: 172.16.0.0\/16,fc00::\/48<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6b64\u65f6svc\u5df2\u7ecf\u53ef\u4ee5\u8c03\u6574ipv6\u7684clusterip\u4e86\uff0c\u53ef\u4ee5\u901a\u8fc7<code>.spec.ipFamilyPolicy<\/code> \u8bbe\u7f6e\u4e3a <code>PreferDualStack<\/code><\/p>\n<p>\u7136\u540e\u8bbe\u5b9aipFamilies:<\/p>\n<pre><code class=\"language-yaml\" lang=\"yaml\">ipFamilies:\n  - IPv6\n  - IPv4\n<\/code><\/pre>\n<p>\u5176\u4e2d\u7b2c\u4e00\u4e2aipfamilies\u4e3a\u9ed8\u8ba4\u503c\uff0c\u5373.spec.ClusterIP\u7684\u503c<\/p>\n<p>\u6b64\u65f6\u8bbe\u7f6e\u4e3a\u4ec5ipv6\uff0c\u90a3\u4e48endpoints\u5c06\u4f1a\u5339\u914d\u4e0d\u5230\u4efb\u4f55\u4e1c\u897f\uff0c\u56e0\u4e3apod\u8fd8\u6ca1\u6709\u5206\u914dipv6,\u6211\u4eec\u9700\u8981\u914d\u7f6ecni\u63d2\u4ef6<\/p>\n<h2 id=\"calico\">calico<\/h2>\n<p>sealos\u4f1a\u9ed8\u8ba4\u5b89\u88c5calico\uff0c\u6211\u4eec\u8fd9\u91cc\u4ec5\u6f14\u793acalico<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">kubectl edit configmap calico-config -n kube-system\n<\/code><\/pre>\n<p>\u4fee\u6539calico\u7684configmap\uff0c\u8fd9\u91cc\u9762\u6709\u4e2ajson\u6587\u4ef6\uff0c\u4fee\u6539\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<pre><code class=\"language-json\" lang=\"json\">\"ipam\": {\n        \"type\": \"calico-ipam\",\n        \"assign_ipv4\": \"true\",\n        \"assign_ipv6\": \"true\"\n    },\n<\/code><\/pre>\n<p>\u4fee\u6539calico \u7684 daemonset \u7684\u73af\u5883\u53d8\u91cf<\/p>\n<pre><code class=\"language-yaml\" lang=\"yaml\">    - name: IP\n      value: \"autodetect\"\n\n    - name: IP6\n      value: \"autodetect\"\n\n    - name: CALICO_IPV4POOL_CIDR\n      value: \"172.16.0.0\/16\"\n\n    - name: CALICO_IPV6POOL_CIDR\n      value: \"fc00::\/48\"\n\n    - name: FELIX_IPV6SUPPORT\n      value: \"true\"\n<\/code><\/pre>\n<p>\u63a5\u7740\u91cd\u542f\u5404\u79cd\u5bb9\u5668\u5c31\u884c\u4e86<\/p>\n<p>\u9a8c\u8bc1\uff1a<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">kubectl get pods pod01 -o go-template --template='{{range .status.podIPs}}{{printf \"%s \\n\" .ip}}{{end}}'\n<\/code><\/pre>\n<p>\u5982\u679cpod\u51fa\u73b0\u4e24\u4e2aip\uff0c\u8bf4\u660e\u6210\u529f\u4e86\uff0c\u53ef\u4ee5\u8bd5\u7740ping\u4e00\u4e0b<\/p>\n<p>\u6211\u4eec\u5f53\u7136\u4e0d\u80fd\u628a\u6240\u6709pod\u63a5\u5165ipv6\uff0c\u5f88\u591a\u7684\u955c\u50cf\u5bf9\u6b64\u5e76\u6ca1\u6709\u652f\u6301\uff0c\u552f\u4e00\u9700\u8981\u914d\u7f6e\u7684\u5176\u5b9e\u662ftraefik<\/p>\n<h2 id=\"traefik\">traefik<\/h2>\n<p>\u5728\u81ea\u5df1helm\u7684traefik\u914d\u7f6e\u4e2d\u6dfb\u52a0\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-yaml\" lang=\"yaml\">service:\n  ipFamilyPolicy: PreferDualStack\n<\/code><\/pre>\n<p>\u7528\u5982\u4e0b\u547d\u4ee4\u68c0\u67e5<\/p>\n<pre><code class=\"language-shell\" lang=\"shell\">kubectl get nodes k8s-linuxpool1-34450317-0 -o go-template --template='{{range .status.addresses}}{{printf \"%s: %s \\n\" .type .address}}{{end}}'\n<\/code><\/pre>\n<p>\u5982\u679c\u8282\u70b9\u6ca1\u6709\u68c0\u6d4b\u5230ipv6\uff0c\u5efa\u8bae\u4f7f\u7528nodeport\u6a21\u5f0f (\u4ee5\u4e0b\u4ec5\u6f14\u793a)<\/p>\n<pre><code class=\"language-yaml\" lang=\"yaml\">deployment:\n  kind: DaemonSet\nports:\n  web:\n    nodePort: 80\n  websecure:\n    nodePort: 443 \nservice:\n  ipFamilyPolicy: PreferDualStack\n<\/code><\/pre>\n<pre><code class=\"language-shell\" lang=\"shell\">helm repo add traefik https:\/\/helm.traefik.io\/traefik\nhelm repo update\nhelm install traefik traefik\/traefik -f traefik-values.yaml --namespace=traefik-v2 --create-namespace\n<\/code><\/pre>\n<p>\u521b\u5efa\u5982\u4e0byaml<\/p>\n<pre><code class=\"language-yaml\" lang=\"yaml\"># dashboard.yaml\napiVersion: traefik.containo.us\/v1alpha1\nkind: IngressRoute\nmetadata:\n  name: dashboard\nspec:\n  entryPoints:\n    - web\n  routes:\n    - match: Host(`traefik.localhost`) &amp;&amp; (PathPrefix(`\/dashboard`) || PathPrefix(`\/api`))\n      kind: Rule\n      services:\n        - name: api@internal\n          kind: TraefikService\n<\/code><\/pre>\n<pre><code class=\"language-yaml\" lang=\"yaml\">kubectl apply -f dashboard.yaml\n<\/code><\/pre>\n<p>\u8bbf\u95ee\u7f51\u7ad9\u82e5\u6210\u529f\u5373\u914d\u7f6e\u6210\u529f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>sealos\u8fdb\u884ck8s\u5b89\u88c5\u4e4b\u540e\u7684\u96c6\u7fa4\uff0c\u672c\u8eab\u662f\u6ca1\u6709ipv6\u652f\u6301\u7684\uff0c\u4e3a\u4e86\u80fd\u5916\u90e8ipv6\u8bbf\u95ee\uff0c\u6211\u4eec\u9700\u8981\u8ba9svc\u548cpod\u8fdb\u884c\u4e00\u4e2aipv6\u652f &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15"}],"version-history":[{"count":1,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":16,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=\/wp\/v2\/posts\/15\/revisions\/16"}],"wp:attachment":[{"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.maoyulong.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}