k8s給pod添加hosts
###
1. 背景
線上待辦功能一直不通,發(fā)現(xiàn)正式環(huán)境的待辦系統(tǒng)域名無法訪問,需要配置hosts。因為應(yīng)用部署在云上,需使用k8s給pod添加域名IP映射。
2. 實戰(zhàn)過程
使用yaml方式創(chuàng)建的pod,使用hostAliases添加域名IP映射,yaml內(nèi)容如下: apiVersion: apps/v1 kind: Deployment metadata: name: smart-pod namespace: default spec: replicas: 1 selector: matchLabels: app: smart-pod template: metadata: labels: app: smart-pod spec: hostAliases: - ip: "10.236.9.220" hostnames: - "intf2.portal.unicom.local" containers: - name: smart-hr image: www.docker.com/images/smart-pod:latest ports: - name: smart-pod-port containerPort: 8090 protocol: TCP
3.修改yaml后,重新啟動pod
# 查看pod kubectl get pods # 刪除pod kubectl delete -f smart-pod.yaml # 創(chuàng)建pod kubectl create -f smart-pod.yaml # 查看pod kubectl get pods
4.查看hosts是否添加成功
kubectl exec smart-pod-name -- cat /etc/hosts
OK, 搞定
###
浙公網(wǎng)安備 33010602011771號