Created
December 5, 2019 03:04
-
-
Save wppurking/ab4d91a84b46fc6d3a70d34f5125b18e to your computer and use it in GitHub Desktop.
hello-wrold k8s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 通过 Deployment 部署 echo-server | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: echo-server | |
name: echo-server | |
spec: | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: echo-server | |
template: | |
metadata: | |
labels: | |
app: echo-server | |
spec: | |
containers: | |
- name: web | |
image: inanimate/echo-server | |
ports: | |
- containerPort: 8080 | |
name: http | |
- containerPort: 8443 | |
name: https | |
--- | |
# 通过 Server 进行 pod 负载均衡 | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: echo-server-srv | |
spec: | |
ports: | |
- port: 80 | |
targetPort: 8080 | |
name: http | |
- port: 443 | |
targetPort: 8443 | |
name: https | |
selector: | |
app: echo-server | |
--- | |
# 初始化 Secret, 给 ingress-nginx 提供验证权限 | |
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: api-basic-auth | |
stringData: | |
wyatt: $apr1$E0aS1JQH$9kZ5YFMvsEOSaTNgyANKk. | |
holly: $apr1$XLNTDv6u$Tpz1UpIfB8qoBriKaqGqE. | |
--- | |
# 部署 ingress 的路由 | |
apiVersion: networking.k8s.io/v1beta1 | |
kind: Ingress | |
metadata: | |
name: echo-server-ig | |
annotations: | |
# type of authentication | |
nginx.ingress.kubernetes.io/auth-type: basic | |
# name of the secret that contains the user/password definitions | |
nginx.ingress.kubernetes.io/auth-secret: api-basic-auth | |
# secret type | |
nginx.ingress.kubernetes.io/auth-secret-type: auth-map | |
# message to display with an appropriate context why the authentication is required | |
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - foo' | |
spec: | |
rules: | |
- host: echo.k8s.ear-data.com | |
http: | |
paths: | |
- backend: | |
serviceName: echo-server-srv | |
servicePort: http | |
- backend: | |
serviceName: echo-server-srv | |
servicePort: https | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment