Skip to content

Instantly share code, notes, and snippets.

@gowatana
Last active December 23, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/3b065d9d800d2b65b82e339bcae5310a to your computer and use it in GitHub Desktop.
Save gowatana/3b065d9d800d2b65b82e339bcae5310a to your computer and use it in GitHub Desktop.
「httpd on Karbon」とコンテナのホスト名が表示される httpd Pod を起動する。
---
kind: Service
apiVersion: v1
metadata:
name: httpd-svc
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
selector:
app: httpd
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: httpd
spec:
replicas: 1
selector:
matchLabels:
app: httpd
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: gowatana/centos7:httpd
ports:
- containerPort: 80
protocol: TCP
command:
- bash
- -c
- |
N=$(uname -n); echo '<h1>httpd on Karbon</h1>' $N > /var/www/html/index.html; httpd -D FOREGROUND
@gowatana
Copy link
Author

gowatana commented Nov 22, 2020

Deployment と Service 作成

$ kubectl apply -f https://gist.githubusercontent.com/gowatana/3b065d9d800d2b65b82e339bcae5310a/raw/httpd-nodeport.yml

アドレスとポート番号を取得

$ IP=$(kubectl get endpoints  kubernetes -o jsonpath='{.subsets[0].addresses[0].ip}')
$ PORT=$(kubectl get service httpd-svc -o jsonpath='{.spec.ports[0].nodePort}')

接続確認

$ echo http://$IP:$PORT
$ curl http://$IP:$PORT
<h1>httpd on Karbon</h1> httpd-5db7885456-kl8fd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment