Notes
Search…
Kubernetes

外部 service

指定 Endpoint

1
kind: Endpoints
2
apiVersion: v1
3
metadata:
4
name: minio
5
subsets:
6
- addresses:
7
- ip: 172.16.1.18
8
ports:
9
- port: 9000
10
11
---
12
kind: Service
13
apiVersion: v1
14
metadata:
15
name: minio
16
spec:
17
ports:
18
- port: 80
19
targetPort: 9000
Copied!

ExternalName

1
kind: Service
2
apiVersion: v1
3
metadata:
4
name: m
5
spec:
6
type: ExternalName
7
externalName: bf-dev-databag.oss-cn-hangzhou-internal.aliyuncs.com
Copied!

安装

1
# 1. 设置免密登录
2
ip="10.4.34.47" && \
3
ssh [email protected]${ip} 'mkdir -p ~/.ssh' && \
4
cat ~/.ssh/id_rsa.pub | ssh [email protected]${ip} 'cat >> ~/.ssh/authorized_keys' && \
5
ssh [email protected]${ip} 'chmod 600 .ssh/authorized_keys'
6
7
# 2. 设置网络、hostname
8
chkconfig NetworkManager on
9
systemctl start NetworkManager.service
10
nmtui
11
12
# 3. 安装常用的工具
13
yum update -y && \
14
yum install -y tree git wget nfs-utils zsh net-tools ntp vim bind-utils traceroute
15
16
# 4. 安装 zsh 和插件
17
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
18
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
19
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
20
21
vi ~/.zshrc
22
change theme to af-magic
23
zsh-syntax-highlighting
24
zsh-autosuggestions
25
alias vi="vim"
26
source ~/.zshrc
27
28
# 5. 关闭防火墙
29
systemctl stop firewalld
30
systemctl disable firewalld
31
32
# 6. 关闭内存交换
33
swapoff -a
34
vi /etc/fstab
35
36
free -h
37
38
# 7. 安装 docker
39
yum remove docker \
40
docker-client \
41
docker-client-latest \
42
docker-common \
43
docker-latest \
44
docker-latest-logrotate \
45
docker-logrotate \
46
docker-selinux \
47
docker-engine-selinux \
48
docker-engine
49
50
rm -rf /var/lib/docker
51
52
yum install -y yum-utils \
53
device-mapper-persistent-data \
54
lvm2
55
56
cat <<EOF > /etc/yum.repos.d/docker-ce.repo
57
[docker-ce-stable]
58
name=Docker CE Stable - \$basearch
59
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/\$basearch/stable
60
enabled=1
61
gpgcheck=1
62
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
63
EOF
64
yum makecache fast
65
66
yum list docker-ce --showduplicates | sort -r
67
yum install -y --setopt=obsoletes=0 docker-ce-17.03.2.ce docker-ce-selinux-17.03.2.ce-1.el7.centos
68
iptables -P FORWARD ACCEPT
69
systemctl enable docker && systemctl start docker
70
71
yum-config-manager --disable docker-ce-stable
72
73
# 8. 安装 Kuberntes
74
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
75
[kubernetes]
76
name=Kubernetes
77
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
78
enabled=1
79
gpgcheck=0
80
repo_gpgcheck=0
81
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
82
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
83
EOF
84
yum makecache fast
85
86
yum list kubelet --showduplicates | sort -r
87
yum list kubeadm --showduplicates | sort -r
88
yum list kubectl --showduplicates | sort -r
89
90
setenforce 0
91
vi /etc/selinux/config
92
SELINUX=disabled
93
94
yum install -y kubernetes-cni-0.6.0 kubelet-1.11.0 kubectl-1.11.0 kubeadm-1.11.0
95
systemctl enable kubelet && systemctl start kubelet
96
yum-config-manager --disable kubernetes
97
98
cat <<EOF > /etc/sysctl.d/k8s.conf
99
net.bridge.bridge-nf-call-ip6tables = 1
100
net.bridge.bridge-nf-call-iptables = 1
101
EOF
102
103
sysctl net.bridge.bridge-nf-call-iptables=1
104
105
sysctl --system
106
107
# docker info | grep cgroup
108
# cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
109
# sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
110
111
DOCKER_CGROUPS=$(docker info | grep 'Cgroup' | cut -d' ' -f3)
112
echo $DOCKER_CGROUPS
113
cat >/etc/sysconfig/kubelet<<EOF
114
KUBELET_EXTRA_ARGS="--cgroup-driver=$DOCKER_CGROUPS --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/bimface_common/pause-amd64:3.1"
115
EOF
116
117
systemctl daemon-reload && systemctl restart kubelet
118
119
# master初始化
120
kubeadm init --config kubeadm/kubeadm.yaml
121
122
mkdir -p $HOME/.kube
123
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
124
sudo chown $(id -u):$(id -g) $HOME/.kube/config
125
126
# 安装网络插件
127
kubectl apply -f flannel/kube-flannel.yml
128
129
# 重置 master
130
kubeadm reset -f
131
ifconfig cni0 down
132
ip link delete cni0
133
ifconfig flannel.1 down
134
ip link delete flannel.1
135
rm -rf /var/lib/cni/
136
rm -rf $HOME/.kube
137
rm -rf /etc/kubernetes
138
139
# 查看 kubelet 日志
140
journalctl -l -u kubelet
141
142
# 确认 kubernetes 安装成功
143
curl http://kubernetes-dashboard.kube-system/api/v1/login/status
144
145
# 重新生产 join token
146
kubeadm token list
147
kubeadm token create
148
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
149
# or
150
kubeadm token create --print-join-command
151
Copied!
Last modified 2yr ago