【问题标题】:How to change the default port of microk8s?如何更改microk8s的默认端口?
【发布时间】:2019-09-08 06:01:41
【问题描述】:

Microk8s 安装在默认端口 16443。我想将其更改为 6443。我使用的是 Ubuntu 16.04。我已经使用 snapd 和 conjure-up 安装了 microk8s。

我尝试过的以下选项均无效。

  1. 试图编辑/snap/microk8s/current/kubeproxy.config 中的端口。由于该卷是只读的,我无法对其进行编辑。
  2. 编辑了/home/user_name/.kube/config 并重新启动了集群。
  3. 尝试使用命令重启集群 sudo kubectl config set clusters.microk8s-cluster.server https://my_ip_address:6443
  4. 尝试使用kubectl proxy --port=6443 --address=0.0.0.0 --accept-hosts=my_ip_address &。它侦听 6443,但仅侦听 HTTP,而不侦听 HTTPS 流量。

【问题讨论】:

    标签: kubernetes microk8s


    【解决方案1】:

    最初在microk8s issue 43 中解决,但在microk8s issue 300 中有详细说明:

    这是用于最新 microk8s 的正确方法:

    #!/bin/bash
    # define our new port number
    API_PORT=8888
    
    # update kube-apiserver args with the new port
    # tell other services about the new port
    sudo find /var/snap/microk8s/current/args -type f -exec sed -i "s/8080/$API_PORT/g" {} ';'
    
    # create new, updated copies of our kubeconfig for kubelet and kubectl to use
    mkdir -p ~/.kube && microk8s.config -l  | sed "s/:8080/:$API_PORT/" | sudo tee /var/snap/microk8s/current/kubelet.config > ~/.kube/microk8s.config
    
    # tell kubelet about the new kubeconfig
    sudo sed -i 's#${SNAP}/configs/kubelet.config#${SNAP_DATA}/kubelet.config#' /var/snap/microk8s/current/args/kubelet
    
    # disable and enable the microk8s snap to restart all services
    sudo snap disable microk8s && sudo snap enable microk8s
    

    【讨论】:

    • 您好 VonC,非常感谢。我可以访问所需端口上的 API 服务器。
    猜你喜欢
    • 1970-01-01
    • 2015-05-24
    • 2016-11-02
    • 2011-10-19
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 2013-08-07
    • 2011-10-31
    相关资源
    最近更新 更多