我已经查看了kong-ingress-controller deployment和getting started文档,并做了提及的所有事情。
一切正常,我可以根据路由访问我的应用程序。但是,当我添加速率限制插件或任何其他插件时,它没有任何效果。
ingress.yaml:
package ndroid.bignerdranch.com; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import java.util.List; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import ndroid.bignerdranch.com.R; public class CrimeListFragment extends Fragment { private RecyclerView mCrimeRecyclerView; private CrimeAdapter mAdapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_crime_list, container, false); mCrimeRecyclerView = (RecyclerView) view .findViewById(R.id.crime_recycler_view); mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); updateUI(); return view; } private void updateUI() { CrimeLab crimeLab = CrimeLab.get(getActivity()); List crimes = crimeLab.getCrimes(); mAdapter = new CrimeAdapter(crimes); mCrimeRecyclerView.setAdapter(mAdapter); } private class CrimeHolder extends RecyclerView.ViewHolder implements View.OnClickListener { private Crime mCrime; private TextView mTitleTextView; private TextView mDateTextView; public CrimeHolder(LayoutInflater inflater, ViewGroup parent) { super(inflater.inflate(R.layout.list_item_crime, parent, false)); itemView.setOnClickListener(this); mTitleTextView = (TextView) itemView.findViewById(R.id.crime_title); mDateTextView = (TextView) itemView.findViewById(R.id.crime_date); } public void bind(Crime crime) { mCrime = crime; mTitleTextView.setText(mCrime.getTitle()); mDateTextView.setText(mCrime.getDate().toString()); } @Override public void onClick(View view) { Toast.makeText(getActivity(), mCrime.getTitle() + " clicked!", Toast.LENGTH_SHORT) .show(); } } private class CrimeAdapter extends RecyclerView.Adapter { private List mCrimes; public CrimeAdapter(List crimes) { mCrimes = crimes; } @Override public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); return new CrimeHolder(layoutInflater, parent); } @Override public void onBindViewHolder(CrimeHolder holder, int position) { Crime crime = mCrimes.get(position); holder.bind(crime); } @Override public int getItemCount() { return mCrimes.size(); } } }
rate-limit.yaml:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: http-ratelimit
labels:
global: 'true'
config:
minute: 5
plugin: rate-limiting
但是限速插件对我的入口没有影响。
注意:kong-ingress-controller在kong名称空间中,而其他资源在默认名称空间中。我尝试将所有内容移到kong命名空间,然后插件可以工作,但服务无法正常工作,因为它在默认命名空间中。
谢谢。
答案 0 :(得分:0)
从Kong docs看,速率限制YAML看起来正确。如果资源配置正确,则Kong不会将请求与入口资源匹配,因为用户没有发送正确的请求。
答案 1 :(得分:0)
KongPlugin,KongIngress应该与Service位于同一命名空间中。 YAML提供的外观正确。 Ingress yamls注释和配置中肯定有问题。您的服务是否使用Ingress对象进行了注释?
答案 2 :(得分:0)
我认为您需要将此注释添加到KongPlugin:
annotations:
kubernetes.io/ingress.class: kong
所以尝试
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: http-ratelimit
annotations:
kubernetes.io/ingress.class: kong
[...]